Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Hibernate
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Configuration and Startup=== If there is a file named import.sql e.g. in the root directory of an [[JEE#beans_jar_file|EJB jar file]] and hibernate.hbm2ddl.auto in the [[JavaJEEJPA#persistence.xml|persistence.xml]] the file is imported at startup of a JBoss application server. ====SessionFactory==== A '''session factory''' represents a particular logical data-store configuration (s.[[Hibernate#hibernate.cfg.xml|hibernate.cfg.xml]]). The [[JavaJEEJPA|JPA]] aquivalent of the session factory is the entity manager factory, the aquivalent of the session factory configuration is the [[JavaJEEJPA#Persistance_Unit|persistence unit]]. In most hibernate applications a SessionFactory should be instantiated once during application initialization. There are advanced options to store the factory like JNDI. A simple and pragmatic approach is to use a static global variable and static initialization (s. example uweheuer application server.HibernateUtil). ====Session==== A '''session''' is a particular unit of work, that means a set of data access operations. The aquivalent in JPA is the [[JavaJEEJPA#Entity_Manager|entity manager]]. ====Startup==== A typical example of a Hibernate startup procedure: SessionFactory sf = new Configuration().configure().buildSessionFactory(); or uweheuerSessionFactory = new AnnotationConfiguration().configure("uweheuer.hibernate.cfg.xml").buildSessionFactory(); When <code>new configuration()</code> is called Hibernate searches for a file named <code>hibernate.properties</code> in the root of the classpath. If found they are loaded into the configuration object. When <code>configure()</code> is called, Hibernate searches for a file named <code>hibernate.cfg.xml</code>. Bei Web Application ist die Ablage unter \WEB-INF\classes. Its possible to have more than one for multiple databases, one for each database (e.g. project 'uweheuer', files uweheuer.hibernate.cfg.xml and uweswiki.hibernate.cfg.xml). ====hibernate.cfg.xml==== <hibernate-configuration> <session-factory> <property name="hbm2ddl.auto">[update|create]</property> Update scheint die beste Einstellung, Änderungen an der Klasse bewirken beim Initialisieren der Anwendung (Reload for a web application) eine Änderung in der zugehörigen Tabelle. Daten gehen nicht verloren. Allerdings werden z.B. neue java long members in der DB mit NULL initialisiert. Dies führt in der Regel zu einer Exception beim Laden.
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width