-->
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.  [ 9 posts ] 
Author Message
 Post subject: javax.servlet.ServletException: duplicate import ?!
PostPosted: Mon Sep 22, 2003 7:28 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
Hi all,

I'm new to Hibernate and is trying to implement the simple 1-to-N relations. I'm ok with the N-to-1 part but trapped in the one-to-many tag.

whenever i uncomment the following code, I'll get:
javax.servlet.ServletException: duplicate import: Parent
Code:
<hibernate-mapping>

   <class name="eg.Parent" table="parent">
      <id name="pid" type="int" unsaved-value="null" >
         <column name="pid" sql-type="int" not-null="true"/>
      </id>
      <property name="name">
         <column name="NAME" sql-type="varchar(10)" not-null="true"/>
      </property>
      <!-- cause duplicate import: Parent
      <set name="children" inverse="true" lazy="true">
         <key column="parent_pid"/>
         <one-to-many class="eq.Child"/>
      </set>
      -->
   </class>

   <class name="eg.Child" table="child">
      <id name="cid" type="int" unsaved-value="null" >
         <column name="cid" sql-type="int" not-null="true"/>
      </id>
      <property name="name">
         <column name="NAME" sql-type="varchar(10)" not-null="true"/>
      </property>
      <many-to-one name="parent" column="parent_pid" class="eg.Parent"/>
   </class>   

</hibernate-mapping>

What mistake did I make?
Thx in advance.


Top
 Profile  
 
 Post subject: Parent <--> Child references
PostPosted: Mon Sep 22, 2003 12:36 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
What do your classes look like? Do you actually have a reference on the Child to the Parent or just and ID?


Top
 Profile  
 
 Post subject: I have both.
PostPosted: Mon Sep 22, 2003 9:23 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
I have the object reference initially. Later I found that I need the id as well to overcome a runtime error. So I have both now:
Code:
public class Child {
    private int cid;
    private String name;
    private Parent parent;
    private int parent_pid;
    // get/set method here ...
}

public class Parent {
    private int pid;
    private String name;
    private Set children;
    // get/set method here ...
}


I do want to let the Child directly get the Parent instance, how can I solve this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2003 9:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Do you have the full stack trace?

Is this your only mapping? The oonly time I've ever seen this is when the same class is inadvertently mapped twice so I'm wondering if you maybe have another mapping file which also defines the class Parent.


Top
 Profile  
 
 Post subject: or is it the Child or Parent problem?
PostPosted: Mon Sep 22, 2003 9:32 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
becoz without the Parent reference to the Child set, the program works fine that the Child can get its Parent.

I got the error when I tried to get the Child set from the Parent...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2003 9:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Again, do you have the full stack trace?

And some hibernate logging would be nice


Top
 Profile  
 
 Post subject: Turn on debugging
PostPosted: Wed Oct 29, 2003 11:55 am 
Beginner
Beginner

Joined: Wed Oct 29, 2003 11:52 am
Posts: 37
Location: Gothenburg, Sweden
The Reference manual is very poor on this. I'm using Hibernate in a Tomcat environment. How do I turn on Hibernate debuggin? (Obviously, I have the same problem with duplicate errors.)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
The Reference manual is very poor on this

On what?

On duplicate import errors? The exception itself seems pretty self-explanatory.

On logging? It uses commons-logging. Here the link to the hibernate docs on logging: http://www.hibernate.org/hib_docs/reference/html/session-configuration.html#session-configuration-s7
Need more info? Check out the commons-logging homepage.

Don't critize docs simply because you choose not to look through them. Peopl have worked hard on these docs. And they are very, very good.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 1:13 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 11:52 am
Posts: 37
Location: Gothenburg, Sweden
My applogies. Being totally unfamiliarized with Apache commons-logging a lot of details seemed to be left out (though the reference doc propably should only focus on it's own details, hence details on external mechanisms is intentionally left out).


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