-->
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.  [ 4 posts ] 
Author Message
 Post subject: @UniqueConstraint involving associated entities
PostPosted: Thu Sep 28, 2006 5:42 am 
Newbie

Joined: Thu Sep 28, 2006 5:16 am
Posts: 1
I'm using JBoss (4.0.4.GA-Patch1) and EJB3 and have found a small inconvinence. Searching the forums reveals similar problems, but I'm unable to see if they are related or even the same thing.

I have one entity bean ("ConsentDecision") reference another ("Sample") through a many-to-one relation. I want to put a unique constraint on ConsentDecision to make sure they are unique in relation to one Sample (I'm not using the real id-field of ConsentDecision but that is unrelated).

So, I add:
@Entity
Code:
@Table(uniqueConstraints =
    { @UniqueConstraint(columnNames = { "storeId", "sample" }) })
public class ConsentDecision implements java.io.Serializable { ... }


to my bean, and this wont work since the field "sample" is defined as:
Code:
@ManyToOne
public Sample getSample() { ... }


This generates an exception:
Quote:
org.hibernate.MappingException: Unable to find column with logical name: ConsentDecision.sample


However, if alter the definition of the relation slighly:
Code:
@ManyToOne
@JoinColumn(name = "sample_pseudosampleid")
public Sample getSample() { ...}


and then the entity definition:
Code:
@Entity
@Table(uniqueConstraints =
    { @UniqueConstraint(columnNames = { "storeId", "sample_pseudosampleid" }) })
public class ConsentDecision implements java.io.Serializable { ...}


This works fine, generating the following SQL (Postgres):
Quote:
...
CONSTRAINT consentdecision_storeid_key UNIQUE (storeid, sample_pseudosampleid)
...


So, my question is: shouldn't it be possible to derive the name from the association field, just like an ordinary field? The name "sample_pseudosampleid" is what is generated by Hibernate on ordinary deployment and should be available somewhere, somehow.

Anyway, hope this helps someone else.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no I'm against that.
you are playing with 2 different notions, properties and columns. No mix and match

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Why is it possible with attributes and not with associations
PostPosted: Wed Nov 29, 2006 9:28 am 
Newbie

Joined: Wed Nov 29, 2006 9:17 am
Posts: 1
Emmanuel, but why is it possible with attributes and not with associations? It seems a bit awkward to me that you have to code like:

Code:
// a state name is unique in the country
@Entity
@Table(uniqueConstraints =
  {@UniqueConstraint(
    columnNames = { "state_Country", "stateName" })})
public class State {

   private Long id;

   private String stateName;

   private Country stateCountry;

...
}


That seems more like mixing concepts. This was tested to work with Hibernate 3.2.1 and ImprovedNamingStrategy. But it does not work if I change the names to:

Code:
    columnNames = { "stateCountry", "stateName" }


AFAIU, these were supposed to be the logical names, right? Am I missing something?

Thanks,
João.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 5:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Now this one is a bug, please create a JIRA issue

_________________
Emmanuel


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