Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

EJB3 Exception:-org.hibernate.exception.SQLGrammarException: could not inse

843830Dec 17 2007 — edited Aug 17 2008
Hi friends
I have develop a entity and session bean(remote and bean) (ejb3). when I am trying to call via client then it throw me this error

11:56:24,843 WARN [JDBCExceptionReporter] SQL Error: -22, SQLState: S0002
11:56:24,843 ERROR [JDBCExceptionReporter] Table not found in statement [insert into tbl_login (username, securecode, password, id) values (?, ?, ?, ?)]
11:56:24,843 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [com.dboys.ejb.entity.TblLogin]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
Caused by: java.sql.SQLException: Table not found in statement [insert into tbl_login (username, securecode, password, id) values (?, ?, ?, ?)]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:349)
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:337)
at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:187)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
... 39 more
11:56:25,156 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@71c1b2
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [com.dboys.ejb.entity.TblLogin]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [com.dboys.ejb.entity.TblLogin]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
... 29 more
Caused by: java.sql.SQLException: Table not found in statement [insert into tbl_login (username, securecode, password, id) values (?, ?, ?, ?)]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:349)
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:337)
at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:187)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
... 39 more



Here I am sending you my entity and session and client code.

Entity
/*
* TblLogin.java
*
* Created on December 17, 2007, 11:03 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.dboys.ejb.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
* Entity class TblLogin
*
* @author UmaShankar
*/
@Entity
@Table(name = "tbl_login")
@NamedQueries( {
@NamedQuery(name = "TblLogin.findById", query = "SELECT t FROM TblLogin t WHERE t.id = :id"),
@NamedQuery(name = "TblLogin.findByUsername", query = "SELECT t FROM TblLogin t WHERE t.username = :username"),
@NamedQuery(name = "TblLogin.findBySecurecode", query = "SELECT t FROM TblLogin t WHERE t.securecode = :securecode"),
@NamedQuery(name = "TblLogin.findByPassword", query = "SELECT t FROM TblLogin t WHERE t.password = :password")
})
public class TblLogin implements Serializable {

@Id
@Column(name = "id", nullable = false)
private Integer id;

@Column(name = "username", nullable = false)
private String username;

@Column(name = "securecode", nullable = false)
private String securecode;

@Column(name = "password", nullable = false)
private String password;

/** Creates a new instance of TblLogin */
public TblLogin() {
}

/**
* Creates a new instance of TblLogin with the specified values.
* @param id the id of the TblLogin
*/
public TblLogin(Integer id) {
this.id = id;
}

/**
* Creates a new instance of TblLogin with the specified values.
* @param id the id of the TblLogin
* @param username the username of the TblLogin
* @param securecode the securecode of the TblLogin
* @param password the password of the TblLogin
*/
public TblLogin(Integer id, String username, String securecode, String password) {
this.id = id;
this.username = username;
this.securecode = securecode;
this.password = password;
}

/**
* Gets the id of this TblLogin.
* @return the id
*/
public Integer getId() {
return this.id;
}

/**
* Sets the id of this TblLogin to the specified value.
* @param id the new id
*/
public void setId(Integer id) {
this.id = id;
}

/**
* Gets the username of this TblLogin.
* @return the username
*/
public String getUsername() {
return this.username;
}

/**
* Sets the username of this TblLogin to the specified value.
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}

/**
* Gets the securecode of this TblLogin.
* @return the securecode
*/
public String getSecurecode() {
return this.securecode;
}

/**
* Sets the securecode of this TblLogin to the specified value.
* @param securecode the new securecode
*/
public void setSecurecode(String securecode) {
this.securecode = securecode;
}

/**
* Gets the password of this TblLogin.
* @return the password
*/
public String getPassword() {
return this.password;
}

/**
* Sets the password of this TblLogin to the specified value.
* @param password the new password
*/
public void setPassword(String password) {
this.password = password;
}

/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the id fields in this object.
* @return a hash code value for this object.
*/
@Override
public int hashCode() {
int hash = 0;
hash += (this.id != null ? this.id.hashCode() : 0);
return hash;
}

/**
* Determines whether another object is equal to this TblLogin. The result is
* <code>true</code> if and only if the argument is not null and is a TblLogin object that
* has the same id field values as this object.
* @param object the reference object with which to compare
* @return <code>true</code> if this object is the same as the argument;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof TblLogin)) {
return false;
}
TblLogin other = (TblLogin)object;
if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
return true;
}

/**
* Returns a string representation of the object. This implementation constructs
* that representation based on the id fields.
* @return a string representation of the object.
*/
@Override
public String toString() {
return "com.dboys.ejb.entity.TblLogin[id=" + id + "]";
}

}


Session
Interface
@Remote
public interface TravelAgentRemote {

/** Creates a new instance of TravelAgentRemote */
//public void createCabin(Cabin cabin);
//public Cabin findCabin(int id);
public void createTblLogin(TblLogin tblLogin);
public TblLogin findTblLogin(int id);
}

Bean
@Stateless
public class TravelAgentBean implements TravelAgentRemote{

/** Creates a new instance of TravelAgentBean */
@PersistenceContext(unitName="dboysPU")
EntityManager manager;

/* public void createCabin(Cabin cabin){
manager.persist(cabin);

}*/


/* public Cabin findCabin(int pKey){
Cabin cab = manager.find(Cabin.class,pKey);
cab.setName("Find Result");
return cab;
}*/

public void createTblLogin(TblLogin tblLogin){
manager.persist(tblLogin);

}

public TblLogin findTblLogin(int pKey){
TblLogin cab = manager.find(TblLogin.class,pKey);
cab.setUsername("NewR");
return cab;
}



}

Here is my ejb client

public class Client {

/** Creates a new instance of Client */
public static void main(String argc[]) {
try{
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("TravelAgentBean/remote");
TravelAgentRemote dao = (TravelAgentRemote)PortableRemoteObject.narrow(ref,TravelAgentRemote.class);


TblLogin tbllogin = new TblLogin();
tbllogin.setId(2);
tbllogin.setUsername("tbluser");
tbllogin.setSecurecode("1002");
tbllogin.setPassword("123456");
dao.createTblLogin(tbllogin);

TblLogin tbllogin1 = dao.findTblLogin(2);
System.out.println(tbllogin1.getId());
System.out.println(tbllogin1.getUsername());
System.out.println(tbllogin1.getSecurecode());
System.out.println(tbllogin1.getPassword());



}catch(javax.naming.NamingException e){
e.printStackTrace();
}
}

can any one help me why this error is occure.

Thanks & Regards
TumoDev
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 14 2008
Added on Dec 17 2007
3 comments
1,883 views