Click here to Skip to main content
15,943,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
/**
 * Description of bankbranchcontactdetailsBean
 *
 * @author Vishal Jain
 */
package com.beans;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Temporal;
import javax.persistence.UniqueConstraint;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import java.util.Date;

@Entity(name = "bankbranchcontactdetails")
@Table(name = "bankbranchcontactdetails", schema = "stserptest", uniqueConstraints = { @UniqueConstraint(columnNames = "BankBranchContactId") })
@TableGenerator(name = "bankbranchcontactdetailsgen", table = "bankbranchcontactdetails", pkColumnName = "BankBranchContactId")
public class bankbranchcontactdetailsBean extends SuperBeanClass implements
        SuperBeanInterface {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(columnDefinition = "mysql->int(10) unsigned", name = "BankBranchContactId", precision = 10, scale = 0, nullable = false, unique = true)
    private Integer _BankBranchContactId;

    @Column(columnDefinition = "mysql->int(10) unsigned", name = "BankBranchId", precision = 10, scale = 0, nullable = false)
    private Integer _BankBranchId;

    @Column(columnDefinition = "mysql->enum('Phone','Mobile','Fax','Telex')", name = "ContactType", length = 6, nullable = false)
    private String _ContactType;

    @Column(columnDefinition = "mysql->varchar(20)", name = "Contact", length = 20, nullable = false)
    private String _Contact;

    public bankbranchcontactdetailsBean() {

        _BankBranchId = 0;
        _ContactType = "";
        _Contact = "";
    }

    public bankbranchcontactdetailsBean(Integer __BankBranchId,
            String __ContactType, String __Contact) {

        _BankBranchId = __BankBranchId;
        _ContactType = __ContactType;
        _Contact = __Contact;
    }

    public Integer getBankBranchId() {
        return _BankBranchId;
    }

    public String getContactType() {
        return _ContactType;
    }

    public String getContact() {
        return _Contact;
    }

    public void setBankBranchId(Integer NewValue) {
        _BankBranchId = NewValue;
    }

    public void setContactType(String NewValue) {
        _ContactType = NewValue;
    }

    public void setContact(String NewValue) {
        _Contact = NewValue;
    }

}

/**
* Description of hibernate.cfg.xml
*/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.default_schema">v32</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<mapping class="com.beans.bankbranchcontactdetailsBean" />

</session-factory>
</hibernate-configuration>


<pre lang="java">
/**
* Description of ManagerClass
*
* @author Vishal Jain
*/
package com.beans;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class ManagerClass {

private static SessionFactory factory = null;
private static ManagerClass _ManagerClass = null;

public static SessionFactory createSessionFactory() {
SessionFactory sessionFactory;
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}

public static SessionFactory getSessionFactory() {
return factory;
}

public static ManagerClass getInstance() throws ExceptionInInitializerError {
try {
if (factory == null) {
factory = createSessionFactory();
}
if (_ManagerClass == null) {
_ManagerClass = new ManagerClass();
}
} catch (Throwable ex) {
JOptionPane.showMessageDialog(
null,
"Failed to create sessionFactory object...\n"
+ ex.getMessage(), "Error...", 0);
throw new ExceptionInInitializerError(ex);
} finally {
return _ManagerClass;
}
}

public ArrayList<Integer> SaveBeansList(Session session, String entityName,
ArrayList<? extends SuperBeanClass> BeansList)
throws HibernateException {
ArrayList<Integer> IDs = null;
try {
IDs = new ArrayList<Integer>();
for (SuperBeanClass element : BeansList) {
IDs.add((Integer) session.save(entityName, element));
}
} catch (HibernateException e) {
throw e;
}
return IDs;
}

public ArrayList<? extends SuperBeanClass> LoadTable(Session session,
String TableName) throws HibernateException {
ArrayList<? extends SuperBeanClass> beansList = null;
try {
beansList = (ArrayList<? extends SuperBeanClass>) session
.createQuery("FROM " + TableName).list();
} catch (HibernateException e) {
throw e;
}
return beansList;
}

public ArrayList<?> LoadConditional(Session session, String _query)
throws HibernateException {
ArrayList<?> beansList = null;
try {
beansList = (ArrayList<? extends SuperBeanClass>) session
.createQuery(_query).list();
} catch (HibernateException e) {
throw e;
}
return beansList;
}

public SuperBeanInterface LoadById(Session session, Class className,
Integer ID) throws HibernateException {
SuperBeanInterface BeanInterface = null;
try {
BeanInterface = (SuperBeanInterface) session.get(className, ID);
} catch (HibernateException e) {
throw e;
}
return BeanInterface;
}

public void DeleteById(Session session, Class className, Integer ID)
throws HibernateException {
try {
session.delete(session.get(className, ID));
} catch (HibernateException e) {
throw e;
}
}
}


/**
* Description of SuperBeanClass
*
* @author Vishal Jain
*/
package com.beans;

public class SuperBeanClass {
public SuperBeanClass() {
}
}


/**
* Description of SuperBeanInterface
*
* @author Vishal Jain
*/
package com.beans;

public interface SuperBeanInterface {
}


OUTPUT

enter code here

ClassName -- FileName -- MethodName -- LineNo.
org.hibernate.exception.internal.SQLExceptionTypeDelegate -- SQLExceptionTypeDelegate.java -- convert -- 82
org.hibernate.exception.internal.StandardSQLExceptionConverter -- StandardSQLExceptionConverter.java -- convert -- 49
org.hibernate.engine.jdbc.spi.SqlExceptionHelper -- SqlExceptionHelper.java -- convert -- 125
org.hibernate.engine.jdbc.spi.SqlExceptionHelper -- SqlExceptionHelper.java -- convert -- 110
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl -- ResultSetReturnImpl.java -- executeUpdate -- 136
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate -- IdentityGenerator.java -- executeAndExtract -- 96
org.hibernate.id.insert.AbstractReturningDelegate -- AbstractReturningDelegate.java -- performInsert -- 58
org.hibernate.persister.entity.AbstractEntityPersister -- AbstractEntityPersister.java -- insert -- 2975
org.hibernate.persister.entity.AbstractEntityPersister -- AbstractEntityPersister.java -- insert -- 3487
org.hibernate.action.internal.EntityIdentityInsertAction -- EntityIdentityInsertAction.java -- execute -- 81
org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- execute -- 377
org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- addResolvedEntityInsertAction -- 214
org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- addInsertAction -- 194
org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- addAction -- 178
org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- addInsertAction -- 321
org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- performSaveOrReplicate -- 286
org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- performSave -- 192
org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- saveWithGeneratedId -- 125
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener -- DefaultSaveOrUpdateEventListener.java -- saveWithGeneratedOrRequestedId -- 206
org.hibernate.event.internal.DefaultSaveEventListener -- DefaultSaveEventListener.java -- saveWithGeneratedOrRequestedId -- 55
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener -- DefaultSaveOrUpdateEventListener.java -- entityIsTransient -- 191
org.hibernate.event.internal.DefaultSaveEventListener -- DefaultSaveEventListener.java -- performSaveOrUpdate -- 49
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener -- DefaultSaveOrUpdateEventListener.java -- onSaveOrUpdate -- 90
org.hibernate.internal.SessionImpl -- SessionImpl.java -- fireSave -- 764
org.hibernate.internal.SessionImpl -- SessionImpl.java -- save -- 756
com.stserp.beans.ManagerClass -- ManagerClass.java -- SaveBeansList -- 60
com.stserp.Program -- Program.java -- main -- 73

could not execute statement

Please help me with the Code as I cannot understand why am I getting this "could not execute statement" error.

I have tried many things, but none of it worked. Some article even suggested to use @cascade = {cascadeType = SAVE_UPDATE} but I don't want to link my table to any other table. I am supposed to maintain all the relations in my code only. There must be some way where tables, if not related to any other table, can be saved. Please help.
Posted
Updated 10-Aug-14 22:53pm
v2

1 solution

Please try implementing Serializable interface for your entity (although this is not imposed by Hibernate). Also rename _BankBranchContactId to id. And enable hibernate_sql logging to see the sql query fired.

This is what is suggested to me and it worked. No Error or so.
But Still Table not being created in the schema stserptest
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900