-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with composite unique key and <properties>
PostPosted: Fri Nov 04, 2005 7:17 am 
Newbie

Joined: Sun Oct 09, 2005 6:36 am
Posts: 19
I'm trying to create a table that has a a unique constraint that consists of multiple columns. After some time i found <properties> and when i use it then i get the correct unique constraint. But the code no longer runs when i try to read some objects using the Criteria API. When the properties are define "as usual" everything works fine, when i wrap them int a <properties> element then hibernate complains that it cannot find the property. Does anyone have a small hint for me?

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="test">

    <class name="Test" table="TEST" lazy="false">    
        <id name="myID" column="ID" access="field">
         <generator class="uuid"/>
        </id>      
      
      <properties name="someName" unique="true">
         <property name="myName" type="string" column="name" access="field" not-null="true"/>      
         <property name="myDomain" type="string" length="16" column="domain" access="field" not-null="true"/>         
      </properties>
      
    </class>         

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
package test;

public class Test
{
   private String myID;
   private String myName;
   private String myDomain;
}

Criteria loCriteria = loSession.createCriteria(Test.class);
               loCriteria.add(Restrictions.eq("myName", "aaa"));               
               return (Test) loCriteria.uniqueResult();

Full stack trace of any exception that occurs:
Code:
org.hibernate.QueryException: could not resolve property: myName of: test.Test
   at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
   at org.hibernate.persister.entity.BasicEntityPersister.getSubclassPropertyTableNumber(BasicEntityPersister.java:1111)
   at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
   at org.hibernate.persister.entity.BasicEntityPersister.toColumns(BasicEntityPersister.java:1086)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:403)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:369)
   at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:42)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:314)
   at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1303)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
   at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:433)


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

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.