-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping join tables... impossible?
PostPosted: Wed Jun 13, 2007 7:30 am 
Newbie

Joined: Wed Jun 13, 2007 7:18 am
Posts: 1
Hello,
I am trying to map join tables but I get the following error :

Code:
org.hibernate.PropertyNotFoundException: field [shelf] not found on fr.mypackage.Product
   at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:122)
   at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:129)
   at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:114)
   at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:137)
   at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:83)
   at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:71)
   at org.hibernate.mapping.ToOne.setTypeUsingReflection(ToOne.java:58)
   at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2174)
   at org.hibernate.cfg.HbmBinder.bindJoin(HbmBinder.java:995)
   at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2107)
   at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2041)
   at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
   at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
   at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
   at org.hibernate.cfg.Configuration.add(Configuration.java:669)
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
   at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
   at fr.epita.yakarouf.util.HibernateUtil.<clinit>(HibernateUtil.java:16)
   at fr.epita.yakarouf.bl.StoreManager.getAllMembers(StoreManager.java:63)
   at fr.epita.yakarouf.action.MemberListAction.execute(MemberListAction.java:21)
   at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
   at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
   at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
   at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
   at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
   at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
   at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Unknown Source)


Here are MySQL tables :

Code:
CREATE TABLE products (
  product_id int(11) NOT NULL auto_increment,
  label text NOT NULL,
  barcode bigint(20) NOT NULL default '0',
  price decimal(12,2) NOT NULL default '0',
  stroke decimal(12,2) NOT NULL default '0',
  tva decimal(12,2) NOT NULL default '0',
  PRIMARY KEY  (product_id)
) TYPE=MyISAM COMMENT='Products table';

CREATE TABLE shelves (
  shelf_id int(11) NOT NULL default '0',
  executive_id int(11) NOT NULL default '0',
  manager_id int(11) NOT NULL default '0',
  label text NOT NULL,
  PRIMARY KEY  (shelf_id)
) TYPE=MyISAM COMMENT='Shelves table';

CREATE TABLE shelf_products (
  shelf_id int(11) NOT NULL default '0',
  product_id int(11) NOT NULL default '0',
  quantity int(11) NOT NULL default '0',
  limit_inf int(11) NOT NULL default '0',
  limit_sup int(11) NOT NULL default '0',
  PRIMARY KEY  (product_id)
) TYPE=MyISAM COMMENT='Shelf products table';


Here are the mappings :

Code:
   <class name="Product" table="products">
      <id
         column="product_id"
         name="id"
         type="integer"
      >
         <generator class="increment" />
      </id>

                ...

      <join table="shelf_products"
         optional="true"
         inverse="true">
         <key column="product_id" />
         <many-to-one
            name="shelf"
            column="shelf_id"
            not-null="true" />
      </join>
   </class>

   <class name="Shelf" table="shelves">
      <id
         column="shelf_id"
         name="id"
         type="integer"
      >
         <generator class="increment" />
      </id>

                ...

      <set name="products"
         table="shelf_products">
         <key column="shelf_id"/>
         <many-to-many column="product_id"
            unique="true"
            class="Product" />
      </set>
      
   </class>


I want a getShelf method for products and a getProducts method for shelves.

Can anyone help me cope with that?

Thanks...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.