-->
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.  [ 3 posts ] 
Author Message
 Post subject: @OneToMany( mappedBy=... ) using wrong grammatical case
PostPosted: Wed Feb 29, 2012 1:36 am 
Newbie

Joined: Wed Feb 29, 2012 12:49 am
Posts: 2
I'm using annotations version 3.4.0.GA to map onto postgresql DB where a lot of fields are case-sensitive. Everything works except this particular bidirectional relationship I just added. Here is the relevant part of setup:

Code:
@Entity
@Table(name= "\"Event\"")
@Filter(name="existent")
public class Event implements Auditable {
 
  @OneToMany(cascade=CascadeType.ALL, mappedBy="event")
  @Filters({
    @Filter(name="unarchived"),
    @Filter(name="existent")
  })
  private Collection<Order> orders;
 
........
}

@Entity
@Filter(name="existent")
@Table(name="\"Order\"")
public class Order implements Auditable, Distributable {

  @ManyToOne(cascade=CascadeType.ALL)
  @JoinColumn(name="\"Event_ID\"")
  @Filter(name="existent")
  private Event event;

..........
}




This is the tail end of a query being generated and I can see the column name Event_ID is not quoted (very last condition in where clause) and thus blowing up. Everywhere else column names work fine. Any idea if this is a bug or I have not setup correctly?


........
left outer join "Event" event8_ on orders0_."Event_ID"=event8_."Event_ID" left outer join "Order_Priority" orderprior9_ on orders0_."Order_Priority_ID"=orderprior9_."Order_Priority_ID" where orders0_."Delete_Timestamp" is null and orders0_."Archive" is null or orders0_."Archive" <> 'Y' and orders0_.Event_ID=?
2012-02-28 23:22:02,301 WARNING [org.hibernate.util.JDBCExceptionReporter] (http-0.0.0.0-8080-8) SQL Error: 0, SQLState: 42703
2012-02-28 23:22:02,302 SEVERE [org.hibernate.util.JDBCExceptionReporter] (http-0.0.0.0-8080-8) ERROR: column orders0_.event_id does not exist
Position: 8
2012-02-28 23:22:02,308 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/photoerp].[Spring MVC Dispatcher Servlet]] (http-0.0.0.0-8080-8) Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception
org.postgresql.util.PSQLException: ERROR: column orders0_.event_id does not exist
Position: 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2019)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1744)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:272)


Top
 Profile  
 
 Post subject: Re: @OneToMany( mappedBy=... ) using wrong grammatical case
PostPosted: Wed Feb 29, 2012 3:21 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I don't think you are supposed to use double quotes to quote your table/column names. The Hibernate documentation only mentions the use of backticks, eg. @Table(name= "`Event`").

http://docs.jboss.org/hibernate/core/3. ... dentifiers

That said, I don't really understand how any problems with the mapping could affect the query in that position (orders0_.Event_ID=?). The join condition between Event and Order is properly quoted (left outer join "Event" event8_ on orders0_."Event_ID"=event8_."Event_ID"). Could it be a problem with one of your filters?


Top
 Profile  
 
 Post subject: Re: @OneToMany( mappedBy=... ) using wrong grammatical case
PostPosted: Wed Feb 29, 2012 12:18 pm 
Newbie

Joined: Wed Feb 29, 2012 12:49 am
Posts: 2
Thanks for the help and documentation reference, I wasn't aware of that. However I've tried without the filters and with backticks to no avail. The filters actually just include the other conditions, orders0_."Delete_Timestamp" is null and orders0_."Archive" is null or orders0_."Archive" <> 'Y', and the backticks are converted to double quotes properly.

It's strange that the join clause is correct as you mentioned but it's the where clause that's no good. That where condition is arising because the code is trying to load the "Order" collection via the "Event" (i.e. the non-owning side of relation). This is working when I have it setup as two unidirectional associations, JoinColumn explicitly defined on both sides, and has only broken when I changed to a single bi-directional to address another part of the system.

Thus the workaround for now is to use unidirectional with non-owning side marked unmodifiable as per hibernate docs:
Code:
  @OneToMany
  @JoinColumn(name = "`Event_ID`", insertable=false, updatable=false)
  private Collection<Order> orders;


But I really think this might be an issue with hibernate implementation and may try to build up a trimmed down example and post to jira if I can find the time. Thanks again.


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