-->
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 problem for manyToMany relation
PostPosted: Sun May 30, 2010 9:27 am 
Newbie

Joined: Sun May 30, 2010 9:11 am
Posts: 1
Hi,

I could not manage to configure my model with annotations

Basicly i need many-many table with additional fields here is my model

Code:
Props
   String name
   List <PropItems> propItems
   
PropItem
   String name

Advert_Props
   Advert advert
   Props props
   PropItem propItem
   String value
   
Advert
   String name
   List<AdvertProps> advertProps



at advert.getAdvertProps i get an exception


Code:
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.dummy.XXXX.core.model.advert.Advert.advertProps#4]
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
   at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249)
   at com.dummy.XXXX.mvc.controller.AdvertController.show(AdvertController.java:276)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:174)
   at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
   at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
   at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
   at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
   at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
   at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
   at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
   at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
   at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:285)
   at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
   at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
   at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
   at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
   at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
   at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417)
   at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343)
   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:112)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:188)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
   at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
   at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
   at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
   at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
   at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
   at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
   at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
   at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
   at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
   at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
   at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
   at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
   at org.mortbay.jetty.Server.handle(Server.java:324)
   at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
   at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
   at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
   at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
   at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
   at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
   at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?tem1_.id as id6_0_, prop?tem1_.displayOrder as displayO2_6_0_, prop?tem1_.props' at line 1
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
   at com.mysql.jdbc.Util.getInstance(Util.java:384)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2264)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
   at org.hibernate.loader.Loader.doQuery(Loader.java:674)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
   ... 86 more


Here is my model



Code:
@Entity
@Table(name = "propItem")
public class PropItem extends AbstractEntity {

   @ManyToOne(targetEntity = Props.class)
   @JoinColumn
   private Props props;

   private String name;
        // Getters Setters
}


Code:
@Entity
@Table(name = "props")
public class Props extends AbstractEntity {
   

   private String title;

   @OneToMany(cascade = CascadeType.ALL, mappedBy = "props")
   @Basic(fetch = FetchType.LAZY, optional = false)
   private List<PropItem> items = new ArrayList<PropItem>();
   // Getters Setters
}



Code:
@Entity
@Table(name = "AdvertProps")
public class AdvertProps extends AbstractEntity {

   @ManyToOne(targetEntity = Advert.class)
   @JoinColumn
   @Basic(fetch = FetchType.LAZY, optional = false)
   private Advert advert;

   @ManyToOne
   @Basic(fetch = FetchType.LAZY, optional = false)
   private Props prop;

   @ManyToOne
   @Basic(fetch = FetchType.LAZY, optional = false)
   private PropItem item;

   private String value;
        // Getters Setters
}



Code:
@Entity
@Table(name = "advert")
public class Advert extends AbstractEntity {

private String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "advert")
   private List<AdvertProps> advertProps = new ArrayList<AdvertProps>();
// Getters Setters
}



and here is my sql statement which causes problem
Code:
select
    advertprop0_.advert_id as advert3_4_,
    advertprop0_.id as id4_,
    advertprop0_.id as id1_3_,
    advertprop0_.advert_id as advert3_1_3_,
    advertprop0_.item_id as item4_1_3_,
    advertprop0_.prop_id as prop5_1_3_,
    advertprop0_.textVal as textVal1_3_,
    propıtem1_.id as id6_0_,
    propıtem1_.displayOrder as displayO2_6_0_,
    propıtem1_.props_id as props5_6_0_,
    propıtem1_.title as title6_0_,
    propıtem1_.value as value6_0_,
    props2_.id as id7_1_,
    props2_.displayOrder as displayO2_7_1_,
    props2_.mandotary as mandotary7_1_,
    props2_.parentId as parentId7_1_,
    props2_.showOnDetails as showOnDe5_7_1_,
    props2_.title as title7_1_,
    props2_.tooltip as tooltip7_1_,
    props2_.type as type7_1_,
    props3_.id as id7_2_,
    props3_.displayOrder as displayO2_7_2_,
    props3_.mandotary as mandotary7_2_,
    props3_.parentId as parentId7_2_,
    props3_.showOnDetails as showOnDe5_7_2_,
    props3_.title as title7_2_,
    props3_.tooltip as tooltip7_2_,
    props3_.type as type7_2_

from
   AdvertProps advertprop0_ left outer join propItem propıtem1_ on advertprop0_.item_id=propıtem1_.id
                      left outer join props props2_ on propıtem1_.props_id=props2_.id
                      left outer join props props3_ on advertprop0_.prop_id=props3_.id
where
   advertprop0_.advert_id=?


mysql executes this query succesfully from console but i get execption
Can anybody help me to find a solution for this model.

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.