-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem with a one-to-one relation
PostPosted: Fri Jul 01, 2005 4:52 am 
Newbie

Joined: Fri Jan 07, 2005 3:57 am
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.8

Mapping documents:

<class name="es.cyii.formuWeb.model.Answer" table="ANSWERS">
...
<one-to-one name="Contact" class="es.cyii.formuWeb.model.Contact"
cascade="save-update"/>
</class>

<class name="es.cyii.formuWeb.model.Contact" table="CONTACTS">
<id name="IdContact" type="integer">
<column name="IDCONTACT"/>
<generator class="sequence">
<param name="sequence">SEQ_CONTACTS</param>
</generator>
</id>
</class>

Code between sessionFactory.openSession() and session.close():

result = (Integer)getHibernateTemplate().save(answer);

Full stack trace of any exception that occurs:

(HibernateTemplate): data integrity violated by SQL 'null'; nested exception is java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("FORMUWEB"."ANSWERS"."IDCONTACT")

Name and version of the database you are using:
Oracle 8.1.6

The generated SQL (show_sql=true):

Hibernate: insert into ANSWERS (ANSWER, ANSWER_DATE, IDANSWER) values (?, ?, ?)


Hi,

I'm developing an app with Hibernate 2.1.8 and I have a problem with a one-to-one relation. As you can see hibernate doesn't generate in the sql the field of the relation. I have tried with the code I have attached and other combinations in the relation mapping, and I have looked for an idea in HiA without results.

I would appreciate any help?

Thanks

Rodolfo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 5:03 am 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
And answer.setContact( contact );? Is the relationship bidirectional?

_________________
- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 5:46 am 
Newbie

Joined: Fri Jan 07, 2005 3:57 am
Posts: 16
Yes,

I do answer.setContact(contact), and contact has his correct values. I can see it with a debugger. The relation is unidirectional from answer to contact.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 6:44 am 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
try:

<one-to-one
name="Contact"
class="es.cyii.formuWeb.model.Contact"
cascade="save-update
constrained="false"
unique="true""/>

Read on the constrained, unique and lazy attributes for more info..

_________________
- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 7:57 am 
Newbie

Joined: Fri Jan 07, 2005 3:57 am
Posts: 16
When I tryed:

<one-to-one name="Contact"
class="es.cyii.formuWeb.model.Contact"
cascade="save-update"
constrained="false"
unique="true"/>

In initialization I obtained.
Caused by: org.xml.sax.SAXParseException: Attribute "unique" must be declared for element type "one-to-one".

And doing
<one-to-one name="Contact"
class="es.cyii.formuWeb.model.Contact"
cascade="save-update"
constrained="false"/>

I obtain the same that before.

org.springframework.dao.DataIntegrityViolationException: (HibernateTemplate): data integrity violated by SQL 'null'; nested exception is java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("FORMUWEB"."ANWERS"."IDCONTACT")
The attribute foreign-key what is the parameter, the name of the foreing key defined in database?
Do you think I must do bidirectional the relation?

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


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

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.