Hi,
I am getting following Exception while saving the model.
I am facing two issues.
1. With Hibernate Batch Update (Does IQ supports batch update through hibernate?)
2. With Identity Generator.
It is working fine without IDENTITY Column and without BATCH Update. Following error I am getting when using GENERATOR.TYPE=AUTO/IDENTITY (Not using Batch insert)
Below are the details.
hibernate.connection.driver_class=com.sybase.jdbc3.jdbc.SybDriver
hibernate.dialect=org.hibernate.dialect.SybaseDialect
Java File
Code:
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;
import com.hp.bto.bsmr.common.util.HibernateUtil;
import com.hp.bto.bsmr.exception.PersistenceException;
import com.hp.bto.bsmr.util.logger.BSMRLogManager;
import com.hp.bto.bsmr.util.logger.BsmrLogger;
/**
* Class is used as a model for CMDB Configuration Related opertaion.
* Annoation are used for hibernate mapping.if any field is not required
* to persist then use @Transient at top of getXXX method for that field.
* If @Transient is not used then that field should be available in database.
* @author Ranveer Kumar Singh.
*
*/
@Entity
@Table(name="DICT_CMDB_DS" )
public class CMDBConfig implements Serializable{
private static BsmrLogger loggerBsmr = BSMRLogManager.getInstance();
private Long id;
private String hostName;
private String userName;
private String password;
private int port;
private Calendar lastColDate;
private int connectionStatus;
private int collectionStatus;
private int colEnabled;
//private Schedule schedule;
public CMDBConfig(String hostName, int port, String userName, String password) {
super();
this.hostName = hostName;
this.port = port;
this.userName = userName;
this.password = password;
}
public CMDBConfig() {
super();
}
@Column (name="ENABLED")
public int getColEnabled() {
return colEnabled;
}
public void setColEnabled(int colEnabled) {
this.colEnabled = colEnabled;
}
@Column (name="COLLECTION_STATUS")
public int getCollectionStatus() {
return collectionStatus;
}
public void setCollectionStatus(int collectionStatus) {
this.collectionStatus = collectionStatus;
}
@Column (name="CONNECTION_STATUS ")
public int getConnectionStatus() {
return connectionStatus;
}
public void setConnectionStatus(int connectionStatus) {
this.connectionStatus = connectionStatus;
}
@Column(name="HOSTNAME")
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
@Id @Column (name="DS_CMDB_ID") @GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column (name="LAST_COLLECTION")
public Calendar getLastColDate() {
return lastColDate;
}
public void setLastColDate(Calendar lastColDate) {
this.lastColDate = lastColDate;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
@Column(name="USERNAME")
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void insert(){
Session session =null;
Transaction tx =null;
boolean error=false;
try{
session = HibernateUtil.getSession();
tx = session.beginTransaction();
session.save(this);
}catch(HibernateException e){
e.printStackTrace();
}finally{
//HandleTransaction();
tx.commit();
HibernateUtil.closeSession();
}
}
public static void main(String[] str){
CMDBConfig config = new CMDBConfig();
config.setUserName("Test");
config.setPassword("Test");
config.setHostName("test");
config.setPort(2638);
// config.setId(123451L);
config.insert();
}
}
Table Detail is as Follows:
Code:
CREATE TABLE DICT_CMDB_DS
(
DS_CMDB_ID INTEGER IDENTITY NOT NULL,
SCHEDULE_ID INTEGER,
HOSTNAME VARCHAR(256),
USERNAME VARCHAR(256),
PASSWORD VARCHAR(256),
PORT NUMERIC(10),
LAST_COLLECTION DATE,
CONNECTION_STATUS NUMERIC(3),
COLLECTION_STATUS NUMERIC(3),
ENABLED NUMERIC(3)
);
Code:
log4j:WARN No such property [target] in org.apache.log4j.FileAppender.
log4j:WARN File option not set for appender [stdout].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
Hibernate: insert into DICT_CMDB_DS (ENABLED, COLLECTION_STATUS, CONNECTION_STATUS , HOSTNAME, LAST_COLLECTION, password, port, USERNAME) values (?, ?, ?, ?, ?, ?, ?, ?)
org.hibernate.exception.GenericJDBCException: could not insert: [com.hp.bto.bsmr.model.bean.CMDBConfig]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2163)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2643)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at CMDBConfig.insert(CMDBConfig.java:223)
at CMDBConfig.main(CMDBConfig.java:241)
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: SQL Anywhere Error -1006000: IQ Internal error. Please report this to Sybase IQ support.
-- (df_Heap.cxx 2310)
at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.updateLoop(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.executeUpdate(Unknown Source)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeUpdate(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 17 more
Exception in thread "main" org.hibernate.AssertionFailure: null id in com.hp.bto.bsmr.model.bean.CMDBConfig entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at CMDBConfig.insert(CMDBConfig.java:229)
at CMDBConfig.main(CMDBConfig.java:241)