Cannot promote key from java int to long hibernate 3 exception

#1

How to fix this exception with hibernate 3 running inside jboss 4 on oracle 11, while trying to change the auto generated key “userver” from int to long (primitive i.e. not Long) due to the default hibernate_sequence having overflowed 2 billion, not wanting constraint errors due to reutilising existing previous keys ? should I use hibernate reverse engineering tool ? should I change hibernate version ?

the field is “userver”

2019-03-31 00:01:11,540 INFO [it.onetech.tserver.login.PreLoginServlet] PreLoginServlet getting session info
2019-03-31 00:01:11,690 ERROR [org.hibernate.property.BasicPropertyAccessor] IllegalArgumentException in class: it.onetech.tserver.beans.profileupdate.UserVersion, setter method of property: userVer
2019-03-31 00:01:11,690 ERROR [org.hibernate.property.BasicPropertyAccessor] expected type: java.lang.Integer, actual value: java.lang.Long
2019-03-31 00:01:11,692 INFO [org.hibernate.event.def.DefaultLoadEventListener] Error performing load command
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of it.onetech.tserver.beans.profileupdate.UserVersion.userVer
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.component.AbstractComponentTuplizer.setPropertyValues(AbstractComponentTuplizer.java:81)
at org.hibernate.tuple.component.PojoComponentTuplizer.setPropertyValues(PojoComponentTuplizer.java:92)
at org.hibernate.type.ComponentType.setPropertyValues(ComponentType.java:358)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:586)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)

should I change it in both this userversion.java which uses UserVersionPK.class :


userversion.java

package it.onetech.tserver.beans.profileupdate;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@ Entity
@ IdClass(UserVersionPK.class)
@ Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class UserVersion {

protected String userId;
protected Integer userVer;

protected String userName;
protected String userPwd;
protected String bundleId;
protected int userState;
protected Date versionDate;

protected Long updateId;

protected boolean publishingEnabled = false;
protected boolean keeytreeAdmin = false;


@ Id
public String getUserId() {
	return userId;
}


public void setUserId(String userId) {
	this.userId = userId;
}


@ Id
public Integer getUserVer() {
	return userVer;
}


public void setUserVer(Integer userVer) {
	this.userVer = userVer;
}


@ Column(name = "user_name")
public String getUserName() {
	return userName;
}


public void setUserName(String userName) {
	this.userName = userName;
}


@ Column(name = "user_pwd")
public String getUserPwd() {
	return userPwd;
}


public void setUserPwd(String userPwd) {
	this.userPwd = userPwd;
}


@ Column(name = "bundle_id")
public String getBundleId() {
	return bundleId;
}


public void setBundleId(String bundleId) {
	this.bundleId = bundleId;
}


@ Column(name = "user_state")
public int getUserState() {
	return userState;
}


public void setUserState(int userState) {
	this.userState = userState;
}


@ Column(name = "version_date")
public Date getVersionDate() {
	return versionDate;
}


public void setVersionDate(Date versionDate) {
	this.versionDate = versionDate;
}


@ Column(name = "pub_admin")
public boolean isPublishingEnabled() {
	return publishingEnabled;
}


public void setPublishingEnabled(boolean publishingEnabled) {
	this.publishingEnabled = publishingEnabled;
}


@ Column(name = "keytree_admin")
public boolean isKeeytreeAdmin() {
	return keeytreeAdmin;
}


public void setKeeytreeAdmin(boolean keeytreeAdmin) {
	this.keeytreeAdmin = keeytreeAdmin;
}


@ Column(name = "update_id")
public Long getUpdateId() {
	return updateId;
}


public void setUpdateId(Long updateId) {
	this.updateId = updateId;
}

}


userverpk.java

package it.onetech.tserver.beans.profileupdate;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

@Embeddable
public class UserVersionPK implements Serializable {

private static final long serialVersionUID = 1L;

private String userId;
private Integer userVer;

public UserVersionPK() {
}

public UserVersionPK(String userId, int userVer) {
	this.userId = userId;
	this.userVer = userVer;
}

@Override
public boolean equals(Object arg0) {
	if (arg0 != null && arg0 instanceof UserVersionPK) {
		UserVersionPK a = (UserVersionPK) arg0;
		return a.getUserId().equals(this.getUserId())
				&& a.getUserVer().toString().equals(
						this.getUserVer().toString());
	} else
		return false;
}

@Override
public int hashCode() {
	StringBuffer concat = new StringBuffer("");
	if (userId != null)
		concat.append(userId);
	if (userVer.toString() != null)
		concat.append(userVer.toString());
	return concat.toString().hashCode();
}

@Column(name = "user_id", nullable = false)
public String getUserId() {
	return userId;
}

public void setUserId(String userId) {
	this.userId = userId;
}

@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "user_ver", nullable = false)
public Integer getUserVer() {
	return userVer;
}

public void setUserVer(Integer userVer) {
	this.userVer = userVer;
}

}

0 Likes