Associations that are related to container management persistence are called managed associations. These are bi-directional associations. Coming to hibernate associations, These are unidirectional.
There are three methods by which an object can be identified.
XDoclet has brought the concept of attribute-oriented programming to Java. Until JDK 1.5, the Java language had no support for annotations; now XDoclet uses the Javadoc tag format (@attribute) to specify class-, field-, or method-level metadata attributes. These attributes are used to generate hibernate mapping file automatically when the application is built. This kind of programming that works on attributes is called as Attribute Oriented Programming.
Session session = getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); MyPersistanceClass mpc = new MyPersistanceClass (“Sample App”); session.save(mpc); tx.commit(); session.close();
The Session and Transaction are the interfaces provided by hibernate. There are many other interfaces besides this.
In order to make most of the things work in hibernate, usually the information is provided in an xml document. This document is called as xml mapping document. The document defines, among other things, how properties of the user defined persistence classes’ map to the columns of the relative tables in database.
<?xml version=”1.0″?> <!DOCTYPE hibernate-mapping PUBLIC “http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd”> <hibernate-mapping> <class name=”sample.MyPersistanceClass” table=”MyPersitaceTable”> <id name=”id” column=”MyPerId”> <generator class=”increment”/> </id> <property name=”text” column=”Persistance_message”/> <many-to-one name=”nxtPer” cascade=”all” column=”NxtPerId”/> </class> </hibernate-mapping>
Everything should be included under <hibernate-mapping> tag. This is the main tag for an xml mapping document.