AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

newbie, problem with hibernate

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Giox
Guest





PostPosted: Tue Dec 26, 2006 9:33 pm    Post subject: newbie, problem with hibernate Reply with quote



Hello everybody,
I'm a beginner in Hibernate and I'm trying to implement a simple
application. At present time I created a MySQL DB and through Eclipse
plugins I generated mapping files. (the DB is pre existing). The
mapping files that I generated contains the following lines:

<hibernate-mapping>
<class name="com.biz.eserciziojsp.Useraccesstable"
table="useraccesstable" catalog="eserciziojsp">
<id name="idUser" type="int">
<column name="idUser" /><generator class="assigned" />
</id>
<property name="userName" type="string">
<column name="userName" length="45" not-null="true"/>
</property>

<set name="userinfos" inverse="true">
<key>
<column name="fkIdUserAccess" not-null="true"/>
</key>
<one-to-many class="com.biz.eserciziojsp.Userinfo" />
</set>
</class>
</hibernate-mapping>

and

<hibernate-mapping>
<class name="com.biz.eserciziojsp.Userinfo" table="userinfo"
catalog="eserciziojsp">
<comment></comment>
<id name="idUser" type="int">
<column name="idUser" />
<generator class="assigned" />
</id>
<many-to-one name="useraccesstable"
class="com.biz.eserciziojsp.Useraccesstable" fetch="select">
<column name="fkIdUserAccess" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>

Now I would like to create a new Userinfo and Useraccesstable element
and make them persistent. The code that I implemented is the following
one.

try
{
localSession = HibernateUtil.getSessionFactory().openSession();
Transaction tx = localSession.beginTransaction();

Useraccesstable localUser = new Useraccesstable();
Userinfo localUserinfo = new Userinfo();

localUser.setUserName(username);


// dopo aver inizializzato l'oggetto localUser, inizializzo il
Set per rendere
// l'associazione bidirezionale
Set localUserinfoes = new HashSet();
localUserinfo.setUseraccesstable(localUser);
localUserinfoes.add(localUserinfo);
localUser.setUserinfos(localUserinfoes);
localSession.saveOrUpdate(localUser);

localSession.saveOrUpdate(localUserinfo);

tx.commit();
}

The code fails calling localSession.saveOrUpdate(localUserinfo); and
the exception says:
"Field 'fkIdUserAccess' doesn't have a default value"
The instruction localSession.saveOrUpdate(localUser); works correctly.
It seems that the code that I wrote doesn't link the two entities
through the foreign key fkIdUserAccess.
Where is my error? Is there someone that can help me?
Thanks Giovanni
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.