[Persistence, JBoss/CMP, Hibernate, Database] - Bad SQL created from EJB QL for simple join - please help!
by Plukh
I'm stuck for the last couple of hours trying to understand what could be causing the following problem on JBoss 4.0.5 GA w/ EJB3.
I have two entities:
| package com.airgonomix.entities;
|
| import javax.persistence.*;
| import java.util.Date;
| import java.util.Collection;
| import java.io.Serializable;
|
| @Entity
| @Table(name="holidays")
| public class Holiday implements Serializable {
|
| private int holidayId;
| private Date holidayStart;
| private Date holidayEnd;
|
| @Id
| @GeneratedValue(strategy = GenerationType.IDENTITY)
| @Column(name="hol_int_holiday_id")
| public int getHolidayId() {
| return holidayId;
| }
|
| public void setHolidayId(int holidayId) {
| this.holidayId = holidayId;
| }
|
| @Column(name="hol_dt_holiday_start")
| @Temporal(TemporalType.DATE)
| public Date getHolidayStart() {
| return holidayStart;
| }
|
| public void setHolidayStart(Date holidayStart) {
| this.holidayStart = holidayStart;
| }
|
| @Column(name="hol_dt_holiday_end")
| @Temporal(TemporalType.DATE)
| public Date getHolidayEnd() {
| return holidayEnd;
| }
|
| public void setHolidayEnd(Date holidayEnd) {
| this.holidayEnd = holidayEnd;
| }
| }
|
and
| package com.airgonomix.entities;
|
| import javax.persistence.*;
| import java.io.Serializable;
|
| @Entity
| @Table(name="holidays_by_tenant")
| @IdClass(HolidayByTenantKey.class)
| public class HolidayByTenant implements Serializable {
| private int holidayId;
| private int tenantId;
| private Tenant tenant;
| private Holiday holiday;
|
| @Id
| @Column(name="hol_int_holiday_id")
| public int getHolidayId() {
| return holidayId;
| }
|
| public void setHolidayId(int holidayId) {
| this.holidayId = holidayId;
| }
|
| @Id
| @Column(name="tnt_int_tenant_id")
| public int getTenantId() {
| return tenantId;
| }
|
| public void setTenantId(int tenantId) {
| this.tenantId = tenantId;
| }
|
| @ManyToOne
| @PrimaryKeyJoinColumn(name="tnt_int_tenant_id", referencedColumnName="tnt_int_tenant_id")
| public Tenant getTenant() {
| return tenant;
| }
|
| public void setTenant(Tenant tenant) {
| this.tenant = tenant;
| }
|
| @ManyToOne
| @PrimaryKeyJoinColumn(name="hol_int_holiday_id", referencedColumnName = "hol_int_holiday_id")
| public Holiday getHoliday() {
| return holiday;
| }
|
| public void setHoliday(Holiday holiday) {
| this.holiday = holiday;
| }
| }
|
The last one references another entity, Tenant, but that's not important right now. All tables and columns are explicitly defined, but I can add a screenshot of the database structure, if it'll help.
Now, I'm trying to execute a very simple query - to fetch all Holidays for a given tenantId:
select hbt.holiday from HolidayByTenant hbt where hbt.tenantId = 1
Hibernate generates the following SQL:
| select
| holiday1_.hol_int_holiday_id as hol1_39_,
| holiday1_.hol_dt_holiday_start as hol2_39_,
| holiday1_.hol_dt_holiday_end as hol3_39_
| from
| holidays_by_tenant holidaybyt0_
| inner join
| holidays holiday1_
| on holidaybyt0_.holiday_hol_int_holiday_id=holiday1_.hol_int_holiday_id
| where
| holidaybyt0_.tnt_int_tenant_id=1
|
Look on what column it's trying to join! holiday_hol_int_holiday_id]!Since I don't have such a column in holidays_by_tenant table in my database, the query fails:
| ...
| Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
| at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
| at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
| at com.airgonomix.ejb.utils.UtilsBean.joinTest(UtilsBean.java:224)
| Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'holidaybyt0_.holiday_hol_int_holiday_id' in 'on clause'
|
What could be the reason for Hibernate to create this field mapping? Any help will be greatly appreciated.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4173296#4173296
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4173296
16 years, 4 months
[JBoss AOP] - Re: Interceptor chain problem
by Kronbe
1) Yes this is the only binding which references to my Interceptor
2) Stacktrace:
| 2008-08-29 12:51:55,800 ERROR [STDERR] java.lang.Exception
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.facades.services.AuthenticationService.cobeco$next$server$authentication$facades$services$AuthenticationService$getClientDirectoryRightsForUser$aop(AuthenticationService.java:282)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.facades.services.AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.invokeNext(AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.java)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.interceptor.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:185)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.facades.services.AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.invokeNext(AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.java)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.interceptor.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:185)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.facades.services.AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.invokeNext(AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.java)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.interceptor.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:185)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.facades.services.AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.invokeNext(AuthenticationService$getClientDirectoryRightsForUser_N1106871331008160416.java)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at cobeco.next.server.authentication.facades.services.AuthenticationService.getClientDirectoryRightsForUser(AuthenticationService.java)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 2008-08-29 12:51:55,800 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
| 2008-08-29 12:51:55,801 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
|
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4173293#4173293
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4173293
16 years, 4 months
[Persistence, JBoss/CMP, Hibernate, Database] - Deadlock unmanaged
by loic
I'm using SEAM with Ejb3 on jboss-4.0.5.GA, with SQL server 2000, driver jtds.
On one of my server i got sometimes deadlock errors :
2008-08-28 17:51:03,381 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1205, SQLState: 40001
| 2008-08-28 17:51:03,381 ERROR [org.hibernate.util.JDBCExceptionReporter] Transaction (Process ID 53) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
| 2008-08-28 17:51:03,381 INFO [STDOUT] Exception during cancel org.hibernate.exception.LockAcquisitionException: could not execute query
| 2008-08-28 17:51:03,381 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.exception.LockAcquisitionException: could not execute query
| 2008-08-28 17:51:03,381 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
| 2008-08-28 17:51:03,381 ERROR [STDERR] at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
| 2008-08-28 17:51:03,381 ERROR [STDERR] at com.edieyes.optixml.ejb3.sessions.StockBean.cancel(StockBean.java:162)
|
The most important matter is that after it (even if i catch the Exception) my next query are all failed.
Here is my part of code failing (on about 1% of time) :
| @Stateless
| public class StockBean implements RemoteStock{
| @PersistenceContext(unitName = "stocktest")
| protected EntityManager em;
|
|
| public void cancel(String orderNumber, String jobNumber) {
| // TODO Auto-generated method stub
| try{
| String query="SELECT c FROM StockReserved as c where c.orderNumber=?1 and c.jobNumber=?2";
| Query q = em.createQuery(query).setParameter(1, orderNumber).setParameter(2,jobNumber);
|
| Iterator iterator =q.getResultList().iterator();
| while(iterator.hasNext()){
| StockReserved stockReserved=(StockReserved) iterator.next();
| String oldCodeArticle=stockReserved.getCodeArticle();
| int oldQuantite=stockReserved.getQuantite();
| int status=stockReserved.getStatus();
| Stock stock=(Stock) em.createQuery("SELECT c FROM Stock c where codeArticle = ?1").setParameter(1,oldCodeArticle).getSingleResult();
| if(status==0)stock.setStockPreReserved(stock.getStockPreReserved()-oldQuantite);
| else if(status==1)stock.setStockReserved(stock.getStockReserved()-oldQuantite);
|
| }
|
|
| query="delete FROM StockReserved as c where c.orderNumber=?1 and c.jobNumber=?2";
| q = em.createQuery(query).setParameter(1, orderNumber).setParameter(2,jobNumber);
| int deleted = q.executeUpdate();
| System.out.println(deleted+" JOBS DELETED ");
|
| /////*****IT FAILS HERE
|
| updateJobNumbers(orderNumber,jobNumber);
|
|
| }catch(Exception e){
|
| System.out.println("Exception during cancel "+e.getMessage());
|
|
| e.printStackTrace();
| }
| }
|
| }
|
|
It's Called like that
| stockService.cancel("000021","001");
|
The best should be not to have anymore this error... but all the tried I did failed.. so if you have a solution?
Else I would like to have a way to go threw that and that the next query won't fail, because for now i have this Exception :
javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
| 2008-08-27 14:52:16,488 ERROR [STDERR] javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
| 2008-08-27 14:52:16,488 ERROR [STDERR] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
|
or this one
| 2008-08-28 17:51:03,490 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: null
| 2008-08-28 17:51:03,490 ERROR [org.hibernate.util.JDBCExceptionReporter] Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=SVR-EDIEYES/553168, BranchQual=, localId=553168]; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=SVR-EDIEYES/553168, BranchQual=, localId=553168])
| 2008-08-28 17:51:03,490 INFO [STDOUT] getSupplementsGridsPriceByFabArea org.hibernate.exception.GenericJDBCException: Cannot open connection
|
THANKS FOR YOUR HELP
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4173292#4173292
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4173292
16 years, 4 months