Hello,
I'm use SC_SNAPSHOT-2011-08-02/EVAL Deployment 2011-08-02
I have entity class OrderItem with @embeddedId
orderItem.ds.xml
when i try fetch data, i see
Ie JPA provider generate incorrect SQL statment:
I'm use SC_SNAPSHOT-2011-08-02/EVAL Deployment 2011-08-02
I have entity class OrderItem with @embeddedId
Code:
@Entity @Table(name="orderItems") public class OrderItem implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId private OrderItemPK id; private BigDecimal quantity; //bi-directional many-to-one association to Item @ManyToOne @JoinColumn(insertable=false, updatable=false) private Item item; //bi-directional many-to-one association to Order @ManyToOne @JoinColumn(insertable=false, updatable=false) private Order order; public OrderItem() { } public OrderItemPK getId() { return this.id; } public void setId(OrderItemPK id) { this.id = id; } public BigDecimal getQuantity() { return this.quantity; } public void setQuantity(BigDecimal quantity) { this.quantity = quantity; } public Item getItem() { return this.item; } public void setItem(Item item) { this.item = item; } public Order getOrder() { return this.order; } public void setOrder(Order order) { this.order = order; } }
Code:
@Embeddable public class OrderItemPK implements Serializable { //default serial version id, required for serializable classes. private static final long serialVersionUID = 1L; @Column(name="order_id") private String orderId; @Column(name="item_id") private String itemId; public OrderItemPK() { } public String getOrderId() { return this.orderId; } public void setOrderId(String orderId) { this.orderId = orderId; } public String getItemId() { return this.itemId; } public void setItemId(String itemId) { this.itemId = itemId; } public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof OrderItemPK)) { return false; } OrderItemPK castOther = (OrderItemPK)other; return this.orderId.equals(castOther.orderId) && this.itemId.equals(castOther.itemId); } public int hashCode() { final int prime = 31; int hash = 17; hash = hash * prime + this.orderId.hashCode(); hash = hash * prime + this.itemId.hashCode(); return hash; } }
Code:
<DataSource ID="orderItem" serverConstructor="com.isomorphic.jpa.JPA2DataSource" beanClassName="com.smarterp.server.orm.OrderItem" schemaBean="com.smarterp.server.orm.OrderItem"> </DataSource>
Code:
=== 2011-08-30 23:56:07,282 [l0-4] DEBUG RPCManager - Processing 1 requests. === 2011-08-30 23:56:07,287 [l0-4] DEBUG DataSource - In DS.forName() for 'orderItem' with DSRequest: com.isomorphic.datasource.DSRequest@3ce02577 === 2011-08-30 23:56:07,288 [l0-4] DEBUG DataSource - Creating instance of DataSource 'orderItem' === 2011-08-30 23:56:07,288 [l0-4] DEBUG RPCManager - Request #1 (DSRequest) payload: { criteria:{ }, operationConfig:{ dataSource:"orderItem", operationType:"fetch", textMatchStyle:"substring" }, startRow:0, endRow:999, componentId:"isc_ListGrid_0", appID:"builtinApplication", operation:"orderItem_fetch", oldValues:{ } } === 2011-08-30 23:56:07,290 [l0-4] INFO IDACall - Performing 1 operation(s) === 2011-08-30 23:56:07,294 [l0-4] DEBUG AppBase - [builtinApplication.orderItem_fetch] No userTypes defined, allowing anyone access to all operations for this application === 2011-08-30 23:56:07,295 [l0-4] DEBUG AppBase - [builtinApplication.orderItem_fetch] No public zero-argument method named '_orderItem_fetch' found, performing generic datasource operation === 2011-08-30 23:56:07,295 [l0-4] DEBUG JPADataSource - [builtinApplication.orderItem_fetch] Creating EntityManager and starting transaction. === 2011-08-30 23:56:07,297 [l0-4] DEBUG DSRequest - [builtinApplication.orderItem_fetch] Clobbering existing FreeResourcesHandler of type 'com.isomorphic.jpa.JPA2DataSource' with a 'com.isomorphic.jpa.JPA2DataSource' === 2011-08-30 23:56:07,297 [l0-4] DEBUG JPA2DataSource - [builtinApplication.orderItem_fetch] Executing fetch. Hibernate: select count((orderitem0_.item_id, orderitem0_.order_id)) as col_0_0_ from orderItems orderitem0_ limit ? 23:56:07,412 WARN JDBCExceptionReporter:233 - SQL Error: 1241, SQLState: 21000 23:56:07,413 ERROR JDBCExceptionReporter:234 - Operand should contain 1 column(s) === 2011-08-30 23:56:07,413 [l0-4] DEBUG JPADataSource - [builtinApplication.orderItem_fetch] Marking transaction for roll back. === 2011-08-30 23:56:07,414 [l0-4] DEBUG JPADataSource - [builtinApplication.orderItem_fetch] Got exception while executing. Transaction will be rolled back. javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148) at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:307) at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getSingleResult(CriteriaQueryCompiler.java:264) at com.isomorphic.jpa.JPA2DataSource.executeFetch(JPA2DataSource.java:304) at com.isomorphic.datasource.DataSource.execute(DataSource.java:1154) at com.isomorphic.jpa.JPADataSource.execute(JPADataSource.java:356) at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:721) at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658) at com.isomorphic.application.AppBase.execute(AppBase.java:491) at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1714) at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:199) at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:156) at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:121) at com.isomorphic.servlet.IDACall.doPost(IDACall.java:73) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 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.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49) 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.content(HttpConnection.java:843) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) Caused by: org.hibernate.exception.DataException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2536) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) at org.hibernate.loader.Loader.list(Loader.java:2271) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:274) ... 32 more Caused by: java.sql.SQLException: Operand should contain 1 column(s) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.doList(Loader.java:2533) ... 40 more === 2011-08-30 23:56:07,415 [l0-4] WARN RequestContext - dsRequest.execute() failed: javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148) at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:307) at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getSingleResult(CriteriaQueryCompiler.java:264) at com.isomorphic.jpa.JPA2DataSource.executeFetch(JPA2DataSource.java:304) at com.isomorphic.datasource.DataSource.execute(DataSource.java:1154) at com.isomorphic.jpa.JPADataSource.execute(JPADataSource.java:356) at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:721) at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658) at com.isomorphic.application.AppBase.execute(AppBase.java:491) at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1714) at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:199) at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:156) at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:121) at com.isomorphic.servlet.IDACall.doPost(IDACall.java:73) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 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.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49) 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.content(HttpConnection.java:843) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) Caused by: org.hibernate.exception.DataException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2536) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) at org.hibernate.loader.Loader.list(Loader.java:2271) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:274) ... 32 more Caused by: java.sql.SQLException: Operand should contain 1 column(s) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.doList(Loader.java:2533) ... 40 more === 2011-08-30 23:56:07,415 [l0-4] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8 === 2011-08-30 23:56:07,415 [l0-4] DEBUG JPADataSource - Rolling back current transaction. === 2011-08-30 23:56:07,417 [l0-4] DEBUG DataSource - In DS.forName() for 'orderItem' with DSRequest: com.isomorphic.datasource.DSRequest@3ce02577 === 2011-08-30 23:56:07,417 [l0-4] DEBUG DataSource - Creating instance of DataSource 'orderItem' === 2011-08-30 23:56:07,417 [l0-4] DEBUG RPCManager - non-DMI response, dropExtraFields: false === 2011-08-30 23:56:07,418 [l0-4] DEBUG JPADataSource - Releasing entity manager.
Code:
select count((orderitem0_.item_id, orderitem0_.order_id)) as col_0_0_ from orderItems orderitem0_ limit ?
Comment