« Return to Thread: How to xml-code a hibernate one-to-one?

Re: How to xml-code a hibernate one-to-one?

by Luiz Eduardo Guida Valmont-2 :: Rate this Message:

| View in Thread

I thought about it too. But that way, it wouldn't be a one-to-one relationship anymore. ;)

customer 1 -> * user

2009/6/29 Rusty Wright <rusty.wright@...>
After re-reading my email I'm now thinking you'd want the unique constraint on the union of both columns customer_id and user_id.  But I'm having trouble visualizing your scenario so I'm not sure if that's right either.  I would think that a customer could consist of multiple users; for example, the customer could be a company and various individuals at that company are users in your database.


Rusty Wright wrote:
> I was wondering about that as well.
>
> I am by no means any sort of a database guru but the way I'd do the ddl
> is I wouldn't have the customer_id in the user table or the user_id in
> the customer table; I'd have a join table that has 2 columns, both
> foreign keys, user_id and customer_id.  You can specify a unique
> constraint on each column by itself which will enforce the 1-to-1
> business rule.  I'd guess that that will be easier to manage, both when
> working with the database and with hibernate.
>
>
> Luiz Eduardo Guida Valmont wrote:
>> Since your user id (uniquely) defines the customer just as the
>> customer id (uniquely) defines the user, you can also merge both
>> entities. Whether that is acceptable or not is a domain-specific problem.
>>
>> 2009/6/26 TheStijn <stijn.geukens@...
>> <mailto:stijn.geukens@...>>
>>
>>
>>     Hi,
>>
>>     I have a table user and a table customer which can be linked by a
>>     one-to-one
>>     relationship; meaning a user can reference 1 customer and vice-versa.
>>
>>     I'm a bit stuck on how to set for instance a customer on a user
>>     since this
>>     customer is not defined yet:
>>
>>     <user user_id="1" ... customer_id="2" />
>>
>>     <customer customer_id="2" ... user_id="1" />
>>
>>     DBUnit throws an SQL exception when trying to insert the user
>> since it
>>     references a customer that was not created yet. The error is logical
>>     since
>>     there is a DB constraint on this field.
>>
>>     My question is, how to go around this problem with DBUnit in XML
>> without
>>     dropping the DB constraint obviously and if possible also without
>>     doing a
>>     'manual' update of user in my unit test?
>>
>>     many thanks,
>>     Stijn
>>     --
>>     View this message in context:
>>
>> http://www.nabble.com/How-to-xml-code-a-hibernate-one-to-one--tp24217768p24217768.html
>>
>>     Sent from the DBUnit - Users mailing list archive at Nabble.com.
>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>>     _______________________________________________
>>     dbunit-user mailing list
>>     dbunit-user@...
>>     <mailto:dbunit-user@...>
>>     https://lists.sourceforge.net/lists/listinfo/dbunit-user
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> ------------------------------------------------------------------------------
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> dbunit-user mailing list
>> dbunit-user@...
>> https://lists.sourceforge.net/lists/listinfo/dbunit-user

------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user


------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user

 « Return to Thread: How to xml-code a hibernate one-to-one?