-->
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.  [ 5 posts ] 
Author Message
 Post subject: Dynamic instantiation with a Collection
PostPosted: Mon Aug 23, 2004 10:25 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
Hibernate version: 2.1.4

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
     
     <class name="com.caliari.nova.ietm.DataModuleInfo" table="DATA_MODULES">
        <id name="id" column="DM_ID" type="string" length="32">
            <generator class="uuid.hex"/>
        </id>
       
        <property name="dmc" column="DMC" type="string" not-null="true"/>
        <property name="type" column="TYPE" type="char"/>
        <property name="techname" column="TECHNAME" type="string"/>
        <property name="note" column="NOTE" type="string" length="4000"/>
       
        <set name="items" inverse="true" cascade="all-delete-orphan">
            <key column="DM_ID"/>
            <one-to-many class="com.caliari.nova.ietm.ItemInfo"/>
        </set>
     </class>
     
     <class name="com.caliari.nova.ietm.ItemInfo" table="IETM_ITEMS">
        <id name="id" column="ITEM_ID" type="string" length="32">
            <generator class="uuid.hex"/>
        </id>
       
        <property name="pn" column="PN" type="string" not-null="true" length="40"/>
        <many-to-one name="dmc" class="com.caliari.nova.ietm.DataModuleInfo" column="DM_ID" cascade="all" not-null="true"/>
       
        <set name="systems" inverse="true" cascade="all-delete-orphan">
            <key column="ITEM_ID"/>
            <one-to-many class="com.caliari.nova.ietm.SystemInfo"/>
        </set>
    </class>
   
    <class name="com.caliari.nova.ietm.SystemInfo" table="IETM_SYSTEMS">
        <id name="id" column="SYSTEM_ID" type="string" length="32">
            <generator class="uuid.hex"/>
        </id>
       
        <property name="name" column="NAME" type="string"/>
        <many-to-one name="item" class="com.caliari.nova.ietm.ItemInfo" column="ITEM_ID" cascade="all" not-null="true"/>
       
        <set name="lcns" table="IETM_LCNS" inverse="true" cascade="all-delete-orphan">
            <key column="SYSTEM_ID"/>
            <element column="LCN" type="string" not-null="true"/>
        </set>
    </class>
     
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
List list = session.find("select new DataModuleInfo(dm.dmc, dm.type, elements(dm.items)) from DataModuleInfo dm");


Full stack trace of any exception that occurs:
Code:
Caused by: net.sf.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.caliari.nova.ietm.DataModuleInfo
        at net.sf.hibernate.util.ReflectHelper.getConstructor(ReflectHelper.java:200)
        at net.sf.hibernate.hql.QueryTranslator.renderSQL(QueryTranslator.java:552)
        at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:155)
        at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
        at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
        at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1561)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
        at com.caliari.util.persistence.PersistentSession.find(PersistentSession.java:86)
        ... 1 more


Name and version of the database you are using: Oracle 9i

Ciao,
I have tried to use projection to instantiate a DataModuleInfo passing a collection to his constructor but ReflectHelper.getConstructor for elements(dm.items) (a collection of ItemInfo) search for a constructor that require only one instance of ItemInfo:
Code:
DataModuleInfo(String, char, ItemInfo)

instead of
Code:
DataModuleInfo(String, char, ItemInfo[])

I have tried other types instead of ItemInfo[] but debugging Hibernate I see that he require only ItemInfo.

Can someone help me? Is possible using collections in dynamic instantiation?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 10:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
AFAIK this is not possible.


Top
 Profile  
 
 Post subject: May be late,but still
PostPosted: Tue Oct 28, 2008 10:04 pm 
Newbie

Joined: Sun Feb 18, 2007 1:05 pm
Posts: 16
I faced the same issue.but got it resolved when I used the fully qualified class name, ie when I prefixed the class name with package name.Anybody face this issue can try out this option

Shaiju


Top
 Profile  
 
 Post subject: May be late,but still
PostPosted: Tue Oct 28, 2008 10:05 pm 
Newbie

Joined: Sun Feb 18, 2007 1:05 pm
Posts: 16
I faced the same issue.but got it resolved when I used the fully qualified class name, ie when I prefixed the class name with package name.Anybody face this issue can try out this option

Shaiju


Top
 Profile  
 
 Post subject: May be late,but still
PostPosted: Tue Oct 28, 2008 10:09 pm 
Newbie

Joined: Sun Feb 18, 2007 1:05 pm
Posts: 16
I faced the same issue.but got it resolved when I used the fully qualified class name, ie when I prefixed the class name with package name.Anybody face this issue can try out this option

Shaiju


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