Hi All,
I am facing the problem in the Saving the record here in my table i have not use the primary key....
my code is
<hibernate-mapping>
<class name="com.solversa.test.TbAddress" table="tb_address" catalog="testhibernate">
<composite-id name="id" class="com.solversa.test.TbAddressId">
<key-property name="addId" type="java.lang.Integer">
<column name="addID" />
</key-property>
<key-property name="address" type="java.lang.String">
<column name="Address" />
</key-property>
<key-property name="addressIndex" type="java.lang.Integer">
<column name="address_index" />
</key-property>
<key-property name="userId" type="java.lang.Integer">
<column name="userId" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
it will create two POJO Classes for the same that is
1:)testMapTest.java
public class TbAddress implements java.io.Serializable {
// Fields
private TbAddressId id;
// Constructors
/** default constructor */
public TbAddress() {
}
// Property accessors
public TbAddressId getId() {
return this.id;
}
public void setId(TbAddressId id) {
this.id = id;
}
and
TbAddressId.java
public class TbAddressId implements java.io.Serializable {
// Fields
private Integer addId;
private String address;
private Integer addressIndex;
private Integer userId;
// Constructors
/** default constructor */
public TbAddressId() {
}
/** full constructor */
public TbAddressId(Integer addId, String address, Integer addressIndex, Integer userId) {
this.addId = addId;
this.address = address;
this.addressIndex = addressIndex;
this.userId = userId;
}
// Property accessors
public Integer getAddId() {
return this.addId;
}
public void setAddId(Integer addId) {
this.addId = addId;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getAddressIndex() {
return this.addressIndex;
}
public void setAddressIndex(Integer addressIndex) {
this.addressIndex = addressIndex;
}
public Integer getUserId() {
return this.userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
and Code for the Inserting the Record is :
org.hibernate.Session session=null;
session= HibernateSessionFactory.getSession();
//Get the Record of the Particular User
//Create the Object the Transaction
org.hibernate.Transaction tx;
//Begin the Transaction
tx=session.beginTransaction();
TbAddressId td=new TbAddressId(10,"Pun00e",5,10);
TbAddress address = new TbAddress();
address.setId(td);
//session.save(td);
session.save(address);
tx.commit();
session.flush();
//close the Session
session.close();
but i am getting this errors:
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:162)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:271)
at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:24)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:719)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:84)
at com.solversa.action.login.execute(login.java:49)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: Table 'testhibernate.testhibernate__tb_address' doesn't exist
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1103)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:853)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:155)
... 27 more
Pls Help me
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html