[Hibernate-JIRA] Created: (HV-230) Database Connective or @Unique
by Ken Egervari (JIRA)
Database Connective or @Unique
------------------------------
Key: HV-230
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-230
Project: Hibernate Validator
Issue Type: New Feature
Affects Versions: 3.1.0.GA
Reporter: Ken Egervari
Priority: Critical
I find a common validation use case is checking to see if a field is unique to all those in the table, such as emails, isbns, usernames, keywords, etc. these fields may not be the primary key, but still need to be unique.
It would be fantastic if hibernate validator implemented this.
This is a common problem though because the domain class will need to have access the database. I dunno if there's an easy way to wire in a copy of sessionFactory to make this easy to write.
Perhaps something like this:
@Query( "select user from User user where user.emailAddress = :this.emailAddress and user.id != :this.id", message = "That Email is already being used by another user in the system" )
private String emailAddress;
Basically the idea is that if @Query returns no results, then the validation constraint is good, and if returns more than 1 result, then it fails. Kind of like simpleJdbcTemplate.queryForMap() does within the Spring testing framework. That method causes the test to fail if no row is returned, because it expects 1 result.
If it were possible to just say
@Unique
private String emailAddress;
That would be extremely concise and would save people a ton of time.
Of course, this requires some interoperability with Hibernate... but I think that's a good thing, no?
Thanks for taking this into consideration. I'd appreciate an email letting me know how to do this in a clean way in 3.1.0 GA as it is as well if you would. Thank you.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 1 month
[Hibernate-JIRA] Created: (HHH-4795) Comparing OneToOne mappedBy column to null generates wrong SQL
by Uros Majeric (JIRA)
Comparing OneToOne mappedBy column to null generates wrong SQL
--------------------------------------------------------------
Key: HHH-4795
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4795
Project: Hibernate Core
Issue Type: Bug
Environment: Hibernate core 3.3.2.GA
Postgresql 8.4
Reporter: Uros Majeric
I have two entities:
@Entity
@Table(name = "beer_keg")
public class Keg implements Serializable {
@Id
@GeneratedValue
@Column(name = "bkid")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToOne(mappedBy="keg", fetch=FetchType.LAZY, optional=true)
public KegValveCombination getCombination() {
return combination;
}
void setCombination(KegValveCombination combination) {
this.combination = combination;
}
}
and
@Entity
@Table(name="keg_valve_combination")
public class KegValveCombination implements Serializable {
@Id
@GeneratedValue
@Column(name="id", nullable=false)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="keg", nullable=false, unique=true)
public Keg getKeg() {
return keg;
}
public void setKeg(Keg keg) {
this.keg = keg;
}
}
if I create query:
em.createQuery("FROM Keg k WHERE k.combination is null").getResultList();
hibernate generates sql like:
select keg0_.* from beer_keg keg0_ where keg0_.bkid is null
but it should be:
select keg0_.* from beer_keg keg0_ left join keg_valve_combination kegvalveco1_ on keg0_.bkid=kegvalveco1_.keg where (kegvalveco1_.keg is null)
thanks, Uros
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 1 month
[Hibernate-JIRA] Created: (HHH-4453) Reserved keywords not quoted in table/column names
by Philipp Reichart (JIRA)
Reserved keywords not quoted in table/column names
--------------------------------------------------
Key: HHH-4453
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4453
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: Hibernate 3.3.1 GA, Windows XP, Sun JDK 1.6.0_06, Derby 10.5
Reporter: Philipp Reichart
I'm currently migrating our test suite form HSQLDB to Derby (we need transaction isolation and the HSLDB 1.9 RCs are no good), and found out that we have a lot of table or colum names that happen to be reserved keywords in Derby, like "transaction", "key", "value", "year", etc..
The usual workaround seems to be adding backticks to any offending table/column name in our hbm.xml files, but that's really an ugly workaround and doesn't prevent later incidents of this kind when new keywords show up in either our mappings or database. As this is about a production database schema, reanming the table/column names isn't an option either.
I already tried implementing a custom Derby dialect and registering all the keywords from the Derby doc at http://db.apache.org/derby/docs/10.5/ref/rrefkeywords29722.html and even defined a "quote everything" NamingStrategy using the dialect to get the correct native quotes for the database.
Unfortunately, neither the Hibernate DDL generator nor HQL queries seem to consider the naming strategy or dialect when handling table or column names.
Is there any way to have Hibernate quote database-specific keywords every they're used?
Or just have Hibernate quote everything that comes from a mapping file?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 1 month