-->
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.  [ 7 posts ] 
Author Message
 Post subject: Common Class in a "many-to-many" relationship
PostPosted: Mon May 10, 2004 9:54 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Hello there,

How can I go on creating a many-to-many relationship in Hibernate with the same Class?

Using the common way I get a "duplicate import" error. :/

Thanks in advance.

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 11:01 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Did you see the red and white text before you posted?

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:11 pm 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
:)
In the meanwhile I've played with it so things have now changed

Hibernate version: 2.1.3


Mapping document

Code:
<hibernate-mapping package="gr.forthnet.openseas.models">   

<class name="Port" table="ports">
        <id name="abbreviation" column="port_id" type="java.lang.String" unsaved-value="null" length="32">
            <generator class="hilo"/>
        </id>

        <property name="name" column="port_name" not-null="true" />
              
        <bag name="destinations" table="fromto" cascade="all" inverse="true" lazy="false">
            <key column="originID"/>
            <many-to-many column="destinationID" class="Port" />
        </bag>          
</class>
</hibernate-mapping>


Stack trace
Code:
Hibernate: select distinct port0_.port_id as port_id, port0_.port_name as port_name from ports port0_
Hibernate: select destinatio0_.destinationID as destinat2___, destinatio0_.originID as originID__, port1_.port_id as port_id0_, port1_.port_name as port_name0_ from fromto destinatio0_ inner join ports port1_ on destinatio0_.destinationID=port1_.port_id where destinatio0_.originID=?
WARN  - SQL Error: 102, SQLState: 42000
ERROR - Incorrect syntax near 'inner'.

WARN  - SQL Error: 102, SQLState: 42000
ERROR - Incorrect syntax near 'inner'.

ERROR - could not initialize collection: [gr.forthnet.openseas.models.Port.destinations#ORE]
com.sybase.jdbc2.jdbc.SybSQLException: Incorrect syntax near 'inner'.

   at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2429)
   at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1865)
   at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
   at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:201)
   at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:182)
   at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybStatement.java:1401)
   at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1386)
   at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:69)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:915)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:890)
   at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
   at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
   at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3259)
   at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:336)
   at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3114)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
   at net.sf.hibernate.loader.Loader.list(Loader.java:946)
   at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1505)
   at gr.forthnet.openseas.HiberDatabase.performQuery(HiberDatabase.java:54)
   at gr.forthnet.openseas.DatabaseClient.generatePorts(DatabaseClient.java:185)
   at gr.forthnet.openseas.DatabaseClient.getPorts(DatabaseClient.java:64)
   at gr.forthnet.openseas.DatabaseClient.generateGreekSortedPorts(DatabaseClient.java:203)
   at gr.forthnet.openseas.DatabaseClient.getGreekSortedPorts(DatabaseClient.java:72)
   at gr.forthnet.openseas.pages.main.Main.updateContext(Main.java:53)
   at gr.forthnet.openseas.servlets.BaseServlet.handleRequest(BaseServlet.java:85)
   at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doRequest(VelocityViewServlet.java:425)
   at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doGet(VelocityViewServlet.java:392)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:551)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:534)


Sybase

ports table
Code:
Column_name      Type     Length     Prec     Scale     Nulls     Default_name     Rule_name     Identity   
---------------  -------  ---------  -------  --------  --------  ---------------  ------------  -----------
port_id          varchar  6          (null)   (null)    false     (null)           (null)        false       
port_name        varchar  40         (null)   (null)    false     (null)           (null)        false       
port_greek_name  varchar  25         (null)   (null)    false     (null)           (null)        false       
port_int_name    varchar  25         (null)   (null)    false     (null)           (null)        false       
area_id          varchar  10         (null)   (null)    true      (null)           (null)        false       
dest_id          varchar  10         (null)   (null)    true      (null)           (null)        false       


fromto table
Code:

Column_name     Type      Length     Prec     Scale     Nulls     Default_name     Rule_name     Identity   
--------------  --------  ---------  -------  --------  --------  ---------------  ------------  -----------
id              smallint  2          (null)   (null)    true      (null)           (null)        false       
origin          varchar   50         (null)   (null)    true      (null)           (null)        false       
originID        varchar   6          (null)   (null)    true      (null)           (null)        false       
destination     varchar   50         (null)   (null)    true      (null)           (null)        false       
destinationID   varchar   6          (null)   (null)    true      (null)           (null)        false       
areaID          smallint  2          (null)   (null)    true      (null)           (null)        false       


Java classes
Code:
public class Port extends Location
{      
   public Port()
   {
      super();
   }

   public Port(String abbreviation, String name)
   {
      super(abbreviation, name);
   }
}


Code:
   protected List origins = new ArrayList();
   protected List destinations = new ArrayList();
   
   public Location()
   {
      super();
   }

   public Location(String abbreviation, String name)
   {
      super(abbreviation, name);
   }
   public List getOrigins() {
   return origins;
   }

   public void setOrigins(List origins) {
      this.origins = origins;
   }
   
   public List getDestinations() {
   return destinations;
   }

   public void setDestinations(List destinations) {
      this.destinations = destinations;
   }
}

Code:
public class Entity
{
   protected String abbreviation;
   protected String name;
   
   public Entity()
   {
      this("", "*");
   }

   public Entity(String abbreviation, String name)
   {
      setAbbreviation(abbreviation);
      setName(name);
   }
      
   public String getAbbreviation() {
   return this.abbreviation;
   }
   
   public String getName() {
   return this.name;
   }
   public void setAbbreviation(String abbreviation) {
      if(abbreviation == null)
         this.abbreviation = "";
      else
         this.abbreviation = abbreviation;
   }
   
   public void setName(String name) {
      if(name == null)
         this.name = "*";
      else
         this.name = name;
   }
}

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Are you using the correct Sybase dialect for your version? Try different ones.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:51 pm 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Well AFAIK there is only one dialect for Sybase (net.sf.hibernate.dialect.SybaseDialect) and that's what I'm using :/

*Not talking about SybaseAnywhere

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 1:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, there is also Sybase11_9_2Dialect


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 2:02 pm 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Awesome!
It worked.

Thanx a lot guys.

I'm sure we'll talk again in the near feature :p I just got started with Hibernate! -> newbie all the way :p

_________________
eu:life
http://www.eulife.gr


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