-->
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.  [ 3 posts ] 
Author Message
 Post subject: wrong uniqueconstraints with oneToMany
PostPosted: Mon Aug 18, 2008 2:58 pm 
Newbie

Joined: Wed Jun 25, 2008 12:10 pm
Posts: 5
hi everyone!

i'm having a 1:n relationship and tried nearly anything to make hibernate create right unique constraints. my last attempt was following code.

Code:
@AccessType("field")
    @CollectionOfElements
    @JoinTable(name = "PRODOFFERS_PRODOFFERPRICES", joinColumns = {
      @JoinColumn(name="PRODUCT_OFFERING_ID", unique = true)           
    },
    inverseJoinColumns = {
      @JoinColumn(name="PRODUCTOFFERINGPRICE_ID", unique = false)
    })
    @OneToMany(cascade = CascadeType.ALL , fetch=FetchType.LAZY)
    public List<ProductOfferingPrice> getProductOfferingPrice() {
        if (productOfferingPrice == null) {
            productOfferingPrice = new ArrayList<ProductOfferingPrice>();
        }
        return this.productOfferingPrice;
    }


i assume that hibernate should create a single unique contraint onto PRODUCT_OFFERING_ID but it does not.
it always creates the productofferingprice_id as unique constraint as well, which is definitely wrong.
i also tried it without the joinColumn and inverseJoinColumn, no way out.
productofferingprice_id will always be generated.


what is wrong with hibernate or with me? ;)

thx in advance

best wishes

chris

PS: yes, i know i should use set instead, but it's generated...
PS: no need for additional code, it is unidirectional.

@edit: same ouput with HSQL and Oracle


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 1:53 am 
Newbie

Joined: Wed Jun 25, 2008 12:10 pm
Posts: 5
again ...

PUBLIC.PRODUCT_OFFERINGS_PRODUCT_OFFER_PRICES
oPUBLIC
+PRODUCT_OFFERINGS_ID
+PRODUCTOFFERINGPRICE_ID
-Indices
-SYS_IDX_SYS_CT_667_669
oUnique: true
oPRODUCTOFFERINGPRICE_ID

is the output hibernate creates for me.
the SQL is created with following annotations.

Code:
@AccessType("field")
@CollectionOfElements
    public List<ProductOfferingPrice> getProductOfferingPrice() {
        if (productOfferingPrice == null) {
            productOfferingPrice = new ArrayList<ProductOfferingPrice>();
        }
        return this.productOfferingPrice;
    }


i need a 1:n relationship between ProductOffering and ProductOfferingPrice.
Why is hibernate creating the UniqueConstraint on the ProductOfferingPrice side of the relationship? .... it's wrong .... ;(

i'm using hibernate 3.2.0ga and 3.2.0ga annotations.

thx in advance

best wishes

chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 2:46 am 
Newbie

Joined: Wed Jun 25, 2008 12:10 pm
Posts: 5
i missed to draw the relation table on a sheet of paper.

if the 1:n is realized with a relation table, you have to think vice versa.

PO_ID | PRO_ID (unique)
-------------------
1 1
1 2
2 3

if you want ProductOffering to have more Prices, the unique has to be on the prices side.
sorry, for the inconvenience, I'm used to the old strategy without a join table.

best wishes

chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.