Here is my mapping file:
Code:
-
<hibernate-mapping>
-
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
-
<class name="test.User" table="users">
-
<id name="uno" type="java.lang.Integer" column="Uno">
<generator class="assigned"/>
</id>
<property name="uname" type="java.lang.String" column="UName" not-null="true" length="25"/>
<!-- associations -->
<!-- bi-directional one-to-many association to Model -->
-
<set name="models" lazy="true" inverse="true">
-
<key>
<column name="Uno"/>
</key>
<one-to-many class="test.Model"/>
</set>
</class>
</hibernate-mapping>
And this is my code
Code:
package test;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
import net.sf.hibernate.Query;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.type.LongType;
public class trytest {
public trytest() {
}
public static void main(String[] args) throws Exception {
Configuration cfg = new Configuration().addClass(User.class);
// new SchemaExport(cfg).create(true, true);
//sessionFactory
SessionFactory sessions = cfg.buildSessionFactory();
//sessionFactory
Session session = sessions.openSession();
//
Transaction tx = session.beginTransaction();
User u1= new User("Maple");
session.save(u1);
session.flush();
tx.commit();
session.close();
session.close();
}
}