-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problems using inheritance
PostPosted: Wed Aug 27, 2003 12:05 pm 
Newbie

Joined: Wed Aug 27, 2003 11:45 am
Posts: 3
Hello, I am having some difficulties using inheritance. I am using one table for the base class and two subclasses.
My mapping file contains this:

<?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="arbolDeTribunales.NodoArbolTribunales" schema="PRUEBA" table="NODOARBOLTRIBUNALES">
<id column="ID" name="id" type="java.lang.Long">

<generator class="sequence">
<param name="sequence">nodoarboltribunales_seq</param>
</generator>
</id>
<discriminator column="clase"/>
<property column="VALORABSOLUTO" length="10" name="valorAbsoluto" not-null="true" type="java.lang.Double"/>
<property column="PADRE" length="10" name="padre" not-null="true" type="java.lang.Long"/>
<property column="DESCRIPCION" length="300" name="descripcion" type="java.lang.String"/>
<property column="CLASE" length="100" name="clase" not-null="true" type="java.lang.String"/>

<subclass name="arbolDeTribunales.Tribunal">
<property column="SIGLAPAPEL" length="100" name="siglaPapel" type="java.lang.String"/>
<property column="SIGLADIGITAL" length="100" name="siglaDigital" type="java.lang.String"/>
</subclass>

<subclass name="arbolDeTribunales.Jerarquia">
</subclass>
</class>

</hibernate-mapping>

and the code is as follows:

public class TestArbol {
public static void main(String[] args) {
net.sf.hibernate.Session aSession=HM.getSession();


Tribunal unTribunal=new Tribunal(new Double(1),new Long(1));
try {
net.sf.hibernate.Transaction tx = aSession.beginTransaction();
aSession.saveOrUpdate(unTribunal);
System.out.println(tx.toString());
tx.commit();
aSession.close();
} catch (HibernateException e) {
e.printStackTrace();
}



}
}

The stack trace I am getting is this:

net.sf.hibernate.transaction.JDBCTransaction@1922f46
27-ago-2003 12:38:47 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
ADVERTENCIA: SQL Error: 957, SQLState: 42000
27-ago-2003 12:38:47 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: ORA-00957: duplicate column name

27-ago-2003 12:38:47 net.sf.hibernate.JDBCException <init>
GRAVE: Could not synchronize database state with session
java.sql.SQLException: ORA-00957: duplicate column name

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
....

Thank you in advance for any help. Mariano


Top
 Profile  
 
 Post subject: Re: Problems using inheritance
PostPosted: Wed Aug 27, 2003 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
matamar wrote:
<property column="CLASE" length="100" name="clase" not-null="true" type="java.lang.String"/>


You have to decide if you want to map this column as the discriminator field or as a property of one of your classes.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 2:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, he can just use:

Code:
<property column="CLASE" length="100" name="clase" not-null="true" type="string" insert="false" update="false"/>


Top
 Profile  
 
 Post subject: still I can
PostPosted: Thu Aug 28, 2003 10:38 am 
Newbie

Joined: Wed Aug 27, 2003 11:45 am
Posts: 3
I tried modifying the line in the hbm fileand replacing it with
"<property column="CLASE" length="100" name="clase" not-null="true" type="string" insert="false" update="false"/>"
, but still does not work.
I am trying to use the column CLASE as a discriminator, as I read in the reference pdf, I assume hibernate can use this column as a discriminator and by default write there the name of the sublcass. Thank you for your comments. Mariano


Top
 Profile  
 
 Post subject: Re: still I can
PostPosted: Thu Aug 28, 2003 11:08 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You may have another duplicate column in your mappings. Either search for it or look at a full "debug" level log output of Hibernate, where you can see the failed SQL query and column name.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Now It
PostPosted: Fri Aug 29, 2003 10:49 am 
Newbie

Joined: Wed Aug 27, 2003 11:45 am
Posts: 3
It took me about a day to find out that I was messing up with my hibernate.prperties files. I am working on three projects that use hibernate, each project uses a different schema. I don


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