Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Object Relational Mapping
org.hibernate.exception.GenericJDBCException
anarkali perera
Ranch Hand
Posts: 237
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my config file
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url"> jdbc:mysql://localhost/hibernatetutorial</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password"></property> <property name="hibernate.connection.pool_size">10</property> <property name="show_sql">true</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.hbm2ddl.auto">update</property> <!-- Mapping files --> <mapping resource="contact.hbm.xml"/> </session-factory> </hibernate-configuration>
this is contact.java file
package roseindia.tutorial.hibernate; /** * @author Deepak Kumar * * Java Class to map to the datbase Contact Table */ public class Contact { private String firstName; private String lastName; private String email; private long id; /** * @return Email */ public String getEmail() { return email; } /** * @return First Name */ public String getFirstName() { return firstName; } /** * @return Last name */ public String getLastName() { return lastName; } /** * @param string Sets the Email */ public void setEmail(String string) { email = string; } /** * @param string Sets the First Name */ public void setFirstName(String string) { firstName = string; } /** * @param string sets the Last Name */ public void setLastName(String string) { lastName = string; } /** * @return ID Returns ID */ public long getId() { return id; } /** * @param l Sets the ID */ public void setId(long l) { id = l; } }
this is hbm file
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="roseindia.tutorial.hibernate.Contact" table="CONTACT"> <id name="id" type="long" column="ID" > <generator class="assigned"/> </id> <property name="firstName"> <column name="FIRSTNAME" /> </property> <property name="lastName"> <column name="LASTNAME"/> </property> <property name="email"> <column name="EMAIL"/> </property> </class> </hibernate-mapping>
this is main class
package roseindia.tutorial.hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; /** * @author Deepak Kumar * * http://www.roseindia.net * Hibernate example to inset data into Contact table */ public class FirstExample { public static void main(String[] args) { Session session = null; try{ // This step will read hibernate.cfg.xml and prepare hibernate for use SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); //Create new instance of Contact and set values in it by reading them from form object System.out.println("Inserting Record"); Contact contact = new Contact(); contact.setId(3); contact.setFirstName("Deepak"); contact.setLastName("Kumar"); contact.setEmail("deepak_38@yahoo.com"); session.save(contact); System.out.println("Done"); }catch(Exception e){ e.printStackTrace(); System.out.println(e.getMessage()); }finally{ // Actual contact insertion will happen at this step session.flush(); session.close(); } } }
but when i run this it gives some ERROR
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. Inserting Record Done Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, name) values (?, ?, ?, ?) Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92) at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:161) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669) at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:38) Caused by: java.sql.BatchUpdateException: General error message from server: "Field 'ID' doesn't have a default value" at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154) ... 6 more
Paul Clapham
Sheriff
Posts: 28400
100
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here's the important line from the stack trace:
Caused by: java.sql.BatchUpdateException: General error message from server: "Field 'ID' doesn't have a default value"
anarkali perera
Ranch Hand
Posts: 237
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
when i making database i make the ID field as a VARCHAR field.Is it wrong?
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
data insert error
Hibernate exception problem
it is giving fatal exception
Batch Update Failure
cannot insert record in MS SQLServer 2000
More...