This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes Hibernate insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate insert " Watch "Hibernate insert " New topic
Author

Hibernate insert

G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
I used hibernate for one of my project in my old company without association

i heared about auto generation tools there in the eclipse so i try to generate the mappling and do code but in the final when i try to the both table it is not working
here i added the codes i am using

please check and let me know if i am wrong anywhere

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.password">Genpact@123</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://localhost:1433/emonitering</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<mapping resource="AmountFlow.hbm.xml"/>
<mapping resource="LoginData.hbm.xml"/>
<mapping resource="ZexpenseTypes.hbm.xml"/>
<mapping resource="ZuserDetail.hbm.xml"/>

</session-factory>
</hibernate-configuration>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 19, 2009 8:17:22 AM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="ZuserDetail" table="zUSER_DETAIL" schema="dbo" catalog="EMONITERING">
<id name="userId" type="int">
<column name="USER_ID" />
<generator class="assigned" />
</id>
<property name="username" type="string">
<column name="USERNAME" length="500" />
</property>
<property name="password" type="string">
<column name="PASSWORD" length="2000" />
</property>
<property name="dob" type="timestamp">
<column name="DOB" length="23" />
</property>
<property name="email" type="string">
<column name="EMAIL" length="200" />
</property>
<property name="paddress" type="string">
<column name="PADDRESS" length="1000" />
</property>
<property name="caddress" type="string">
<column name="CADDRESS" length="1000" />
</property>
<property name="status" type="java.lang.Character">
<column name="STATUS" length="1" />
</property>
<property name="createTimeStamp" type="timestamp">
<column name="CREATE_TIME_STAMP" length="23" />
</property>
<set name="loginDatas" inverse="true" lazy="true" table="LOGIN_DATA" fetch="select">
<key>
<column name="USER_ID" />
</key>
<one-to-many class="LoginData" />
</set>
</class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 19, 2009 8:17:22 AM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="LoginData" table="LOGIN_DATA" schema="dbo" catalog="EMONITERING">
<id name="loginTypeId" type="int">
<column name="LOGIN_TYPE_ID" />
<generator class="assigned" />
</id>
<many-to-one name="zuserDetail" class="ZuserDetail" fetch="select">
<column name="USER_ID" />
</many-to-one>
<property name="loginType" type="string">
<column name="LOGIN_TYPE" length="50" />
</property>
<property name="username" type="string">
<column name="USERNAME" length="50" />
</property>
<property name="password" type="binary">
<column name="PASSWORD" />
</property>
<property name="status" type="java.lang.Character">
<column name="STATUS" length="1" />
</property>
<property name="createdTimeStamp" type="timestamp">
<column name="CREATED_TIME_STAMP" length="23" />
</property>
</class>
</hibernate-mapping>
System.out.println(getSession().createQuery("from ZuserDetail").list());
ZuserDetail p1 =new ZuserDetail();
p1.setUserId(3);
p1.setUsername("se");
p1.setPassword("");
p1.setCaddress("");
p1.setPaddress("");
p1.setEmail("");
p1.setDob(new java.util.Date("01/01/09"));
p1.setCreateTimeStamp(new java.util.Date("01/01/09"));


System.out.println("usersaved");
//ZuserDetail p = (ZuserDetail)getSession().createQuery("from ZuserDetail").list().get(0);
LoginData o = new LoginData();
o.setUsername(p1.getUsername());
o.setLoginType("d");
o.setStatus('d');
o.setZuserDetail(p1);
o.setCreatedTimeStamp(new java.util.Date("01/01/09"));
o.setPassword(new byte[8]);
java.util.Set<LoginData> st = new java.util.HashSet<LoginData>();
st.add(o);
p1.setLoginDatas(st);
try{
getSession().save(p1);
getSession().save(o);
}
catch(Exception e)
{e.printStackTrace();}

Thanks
Sathish kumar
SCJP, SCWCD
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

http://faq.javaranch.com/java/UseCodeTags
http://faq.javaranch.com/java/CarefullyChooseOneForum


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
Maneesh Godbole wrote:http://faq.javaranch.com/java/UseCodeTags
http://faq.javaranch.com/java/CarefullyChooseOneForum


can i know what you not understanding with that?

this the problem i came acors so i posted and the problem is about hibernate association and i am not ready to waste the others time as well my time so if you know please let me know the answers
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Did you read the links I had provided?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags as requested. You can edit your post to include them using the button or re-post the question with proper formatting.
G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
David Newton wrote:Please UseCodeTags as requested. You can edit your post to include them using the button or re-post the question with proper formatting.



could anyone please help me to delete this message.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate insert