-->
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.  [ 8 posts ] 
Author Message
 Post subject: Inheritance mapping problem
PostPosted: Thu Jun 09, 2005 9:17 am 
Regular
Regular

Joined: Mon Apr 25, 2005 5:36 am
Posts: 103
what's wrong with that :

In my class :

<class>

<id name="Id" type="java.lang.Integer">
<column name="ID" not-null="true" unique="true" sql-type="NUMBER(6)" />
<generator class="assigned" />
</id>
....
<joined-subclass name="Externe" table="EXTERNE" >
<key column="Id"/>
<property name="MontantFacturation" column="MONTANTFACTURATION"/>
</joined-subclass>

<joined-subclass name="Interne" table="INTERNE" >
<key column="Id"/>
<property name="SalaireMensuel" column="SALAIREMENSUEL"/>
</joined-subclass>

</class>



In my subclass :

<class name="fr.icdc.dei.fwk.sample.dto.Interne" table="INTERNE" schema="HIBERNATE">
<id name="Id" type="java.lang.Integer">
<column name="ID" not-null="true" unique="true" sql-type="NUMBER(6)" />
<generator class="assigned" />
</id>
<property name="SalaireMensuel" type="java.math.BigDecimal">
<column name="SALAIREMENSUEL" not-null="false" sql-type="NUMBER(8,2)" />
</property>
</class>
</hibernate-mapping>


AND



<class name="fr.icdc.dei.fwk.sample.dto.Externe" table="EXTERNE" schema="HIBERNATE">
<id name="Id" type="java.lang.Integer">
<column name="ID" scale="6" precision="0" not-null="true" unique="true" sql-type="NUMBER" />
<generator class="assigned" />
</id>
<property name="MontantFacturation" type="java.math.BigDecimal">
<column name="MONTANTFACTURATION" not-null="true" sql-type="NUMBER(8,2)" />
</property>
</class>
</hibernate-mapping>



I got that:
Initial SessionFactory creation failed
java.lang.ExceptionInInitializerError
at fr.icdc.dei.fwk.test.HibernateUtil.<clinit>(HibernateUtil.java:22)
at fr.icdc.dei.fwk.test.Test.main(Test.java:15)
Caused by: org.hibernate.MappingException: Error reading resource: fr/icdc/dei/fwk/sample/dto/Ressource.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1392)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1364)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1346)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1313)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1241)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1227)
at fr.icdc.dei.fwk.test.HibernateUtil.<clinit>(HibernateUtil.java:16)
... 1 more
Caused by: org.hibernate.MappingException: duplicate import: Externe
at org.hibernate.cfg.Mappings.addImport(Mappings.java:101)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:540)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:487)
at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.java:758)
at org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.java:1791)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1732)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:317)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:235)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:151)
at org.hibernate.cfg.Configuration.add(Configuration.java:358)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:395)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 8 more
Exception in thread "main"




what's wrong?


Top
 Profile  
 
 Post subject: Re: Inheritance mapping problem
PostPosted: Thu Jun 09, 2005 9:38 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
julientarrago wrote:
what's wrong with that :

In my class :

<class>

<id name="Id" type="java.lang.Integer">
<column name="ID" not-null="true" unique="true" sql-type="NUMBER(6)" />
<generator class="assigned" />
</id>
....
<joined-subclass name="Externe" table="EXTERNE" >
<key column="Id"/>
<property name="MontantFacturation" column="MONTANTFACTURATION"/>
</joined-subclass>

<joined-subclass name="Interne" table="INTERNE" >
<key column="Id"/>
<property name="SalaireMensuel" column="SALAIREMENSUEL"/>
</joined-subclass>

</class>



In my subclass :

<class name="fr.icdc.dei.fwk.sample.dto.Interne" table="INTERNE" schema="HIBERNATE">
<id name="Id" type="java.lang.Integer">
<column name="ID" not-null="true" unique="true" sql-type="NUMBER(6)" />
<generator class="assigned" />
</id>
<property name="SalaireMensuel" type="java.math.BigDecimal">
<column name="SALAIREMENSUEL" not-null="false" sql-type="NUMBER(8,2)" />
</property>
</class>
</hibernate-mapping>


AND



<class name="fr.icdc.dei.fwk.sample.dto.Externe" table="EXTERNE" schema="HIBERNATE">
<id name="Id" type="java.lang.Integer">
<column name="ID" scale="6" precision="0" not-null="true" unique="true" sql-type="NUMBER" />
<generator class="assigned" />
</id>
<property name="MontantFacturation" type="java.math.BigDecimal">
<column name="MONTANTFACTURATION" not-null="true" sql-type="NUMBER(8,2)" />
</property>
</class>
</hibernate-mapping>

....
what's wrong?


You have two classes (one a joined-subclass) named Externe which is causing the conflict. By default, Hibernate assumes that all class names, regardless of package, will be unique and allows you to simplify the Query language statements by just using the unqualified class name. If you truely have two classes with the same name, Externe and fr.icdc.dei.fwk.sample.dto.Externe, then you can specify auto-import=false and it will use the fully qualified class names.

You should also look at the docs for <import> configuration as well.

Note: I haven't had to use this myself so I'm not sure what other side-effects this may cause.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 9:43 am 
Regular
Regular

Joined: Mon Apr 25, 2005 5:36 am
Posts: 103
but Extern is my subclass I have mapped it in a hbm.xml file.

It is the same file. I don't understand what to do?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 9:48 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
julientarrago wrote:
but Extern is my subclass I have mapped it in a hbm.xml file.

It is the same file. I don't understand what to do?


You should probably read more about joined subclasses. If it's the same class, you don't need to also map it as a <class>. A joined-subclass is a top-level mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 9:49 am 
Regular
Regular

Joined: Mon Apr 25, 2005 5:36 am
Posts: 103
pksiv wrote:
julientarrago wrote:
but Extern is my subclass I have mapped it in a hbm.xml file.

It is the same file. I don't understand what to do?


You should probably read more about joined subclasses. If it's the same class, you don't need to also map it as a <class>. A joined-subclass is a top-level mapping.




thanks I have just find this soluce thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 9:57 am 
Regular
Regular

Joined: Mon Apr 25, 2005 5:36 am
Posts: 103
julientarrago wrote:
pksiv wrote:
julientarrago wrote:
but Extern is my subclass I have mapped it in a hbm.xml file.

It is the same file. I don't understand what to do?


You should probably read more about joined subclasses. If it's the same class, you don't need to also map it as a <class>. A joined-subclass is a top-level mapping.




thanks I have just find this soluce thanks




And now How can I precise the sql-type for the property?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 9:59 am 
Regular
Regular

Joined: Mon Apr 25, 2005 5:36 am
Posts: 103
julientarrago wrote:
julientarrago wrote:
pksiv wrote:
julientarrago wrote:
but Extern is my subclass I have mapped it in a hbm.xml file.

It is the same file. I don't understand what to do?


You should probably read more about joined subclasses. If it's the same class, you don't need to also map it as a <class>. A joined-subclass is a top-level mapping.




thanks I have just find this soluce thanks




And now How can I precise the sql-type for the property?



ok ok I find it


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 10:28 am 
Regular
Regular

Joined: Mon Apr 25, 2005 5:36 am
Posts: 103
julientarrago wrote:
julientarrago wrote:
julientarrago wrote:
pksiv wrote:
julientarrago wrote:
but Extern is my subclass I have mapped it in a hbm.xml file.

It is the same file. I don't understand what to do?


You should probably read more about joined subclasses. If it's the same class, you don't need to also map it as a <class>. A joined-subclass is a top-level mapping.




thanks I have just find this soluce thanks




And now How can I precise the sql-type for the property?



ok ok I find it




this is my java file of one subclass :




package fr.icdc.dei.fwk.sample.dto;


public class Externe extends Ressource implements java.io.Serializable {

// Fields

private java.lang.Integer Id;
private java.math.BigDecimal MontantFacturation;


// Constructors

/** default constructor */
public Externe() {
}

/** constructor with id */
public Externe(java.lang.Integer Id) {
this.Id = Id;
}




// Property accessors
/**

*/

public java.lang.Integer getId () {
return this.Id;
}

public void setId (java.lang.Integer Id) {
this.Id = Id;
}
/**

*/

public java.math.BigDecimal getMontantFacturation () {
return this.MontantFacturation;
}

public void setMontantFacturation (java.math.BigDecimal MontantFacturation) {
this.MontantFacturation = MontantFacturation;
}




}


is it correct?


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