-->
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: Declarde a Set with lazy accociation and using Criteria
PostPosted: Fri Nov 05, 2004 9:36 am 
Newbie

Joined: Fri Nov 05, 2004 8:48 am
Posts: 3
Location: Germany, Hamburg
Hello,

at first excuse my English. I am not a native speaker.

I am using hibernate first time and read a lot of Hibernatesdocuments but i can't found solution. Maby you can give tip.

The situation:
The Problem: An Object "Catalog" can contain more than one Languagedefinitions. The definition contain the local code (two letters like us, en, de....)

I choose a Set between Catalog and CatalogLanguage because in a Set can't be more than one same Language. I tried the Accociation with lazy="true" and lazy="false". Everything works fine :-).


The Code works fine and load everytime all Languagedefinitions of the Object "Catalog".
But i would like to load the Object "Catalog" only with one(!) Languagedefinition (I mean only one Element in the Set with the LocalCode = us for example).

I tried some HQL-Statements but i got all the time Errors with the
[...]
INFO StandardQueryCache:41 - starting query cache at region: net.sf.hibernate.cache.StandardQueryCache
net.sf.hibernate.QueryException: unexpected token: as [from CatalogLanguage as scl where scl.localCode=us]
[...]

Can i load from a collection Set only one Element and how?

Thanxx
Marc

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

<hibernate-mapping>
<class name="Catalog" table="CATALOG">
<id name="id" type="int" column="CATALOG_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>

<set name="languages" table="CATALOG_LANGUAGES" lazy="true" cascade="all">
<key column="CATALOG_ID"/>
<composite-element class="CatalogLanguage">

<property name="localeCode" type="string">
<column name="LOCALCODE" not-null="true"/>
</property>

<property name="headline" type="string">
<column name="HEADLINE" not-null="true"/>
</property>

</composite-element>
</set>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
c = (Catalog)session.get(ShopCategory.class, CatalogId );

Hibernate.initialize( sc.getCategoryLanguage() );

tx.commit();
HibernateUtil.closeSession();


Name and version of the database you are using:
Hipersonic


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.