直接从3.5(特别是hibernate3.jar)迁移到4.3.5。应用程序是使用基本JAXB(@XMLRootElement等)注释的简单POJO。另外,简单的hbm.xml和cfg.xml。由不起眼的持久性类用于PostgreSQL数据库。操作系统是Fedora20。修复了编译错误,例如hibernate.org DTD位置。
所有表的错误是“未知实体”。我需要说,“它看起来应该有效,但不是。”会很感激。提前谢谢了。 -MB
Hibernate .jar文件增量(在类路径中):
PREVIOUS:
NEW:
CONFIGURATION FILE:
<?xml version='1.0' encoding='utf-8'?>
<!--
~ Copyright (c) 2006 - 2014 Make Sence Florida Inc.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.ejb.naming_strategy">
org.hibernate.cfg.DefaultComponentSafeNamingStrategy
</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="com/project/modules/security/types/SecurityPrincipalEntity.hbm.xml"/>
</session-factory>
</hibernate-configuration>
POJO:
package com.project.modules.security.types;
/*
* Copyright (c) 2006 - 2014 Make Sence Florida Inc.
*/
import com.project.modules.persist.entity.EntityBase;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@XmlRootElement(name = "principal")
@XmlAccessorType(XmlAccessType.FIELD)
public class SecurityPrincipalEntity extends EntityBase<Long> {
private static final long serialVersionUID = 130656661920374675L;
@XmlAttribute(required = false)
private Long key;
@XmlTransient
private Long version;
@XmlElement(required = true, name = "user_name")
private String user_name;
@XmlElement(required = true, name = "user_password")
private String user_password;
public SecurityPrincipalEntity() {
}
public SecurityPrincipalEntity(String target) {
this.user_name = target;
}
public Long getVersion() {
return version;
}
public String getUser_name() {
return user_name;
}
public String getUser_password() {
return user_password;
}
public Long getKey() {
return key;
}
public void writeTo(DataOutputStream out) throws IOException {
}
public void readFrom(DataInputStream in)
throws IOException, IllegalAccessException, InstantiationException {
}
}
的hbm.xml:
<?xml version="1.0"?>
<!--
~ Copyright (c) 2006 - 2014 Make Sence Florida Inc.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.project.modules.security.types">
<class name="com.project.modules.security.types.SecurityPrincipalEntity"
table="security_principal">
<id access="field" name="key" type="long">
<generator class="identity"/>
</id>
<version access="field" name="version" type="long"/>
<property access="field" name="user_name" type="string">
<column name="user_name" length="2048"/>
</property>
<property access="field" name="user_password" type="string">
<column name="user_password" length="2048"/>
</property>
</class>
</hibernate-mapping>
PERSISTER CLASS:
package com.project.modules.security.types;
import com.project.modules.foundation.topology.datasource.DataSourceType;
import com.project.modules.persist.Persist;
import com.project.modules.persist.PersistException;
import com.project.modules.persist.entity.EntityPersisterBase;
import org.hibernate.Query;
/*
* Copyright (c) 2006 - 2014 Make Sence Florida Inc.
*/
public class PrincipalPersister extends EntityPersisterBase<Long, SecurityPrincipalEntity> {
private static final long serialVersionUID = -49958433413782923L;
@Override
public DataSourceType getType() {
return DataSourceType.Discovery;
}
@Override
protected SecurityPrincipalEntity createNewPersistedClass() throws PersistException {
try {
return new SecurityPrincipalEntity();
} catch (Throwable e) {
throw new PersistException(e);
}
}
@Override
protected Query getDeleteAllEntitiesQuery() {
return Persist.session(getType()).createQuery("delete from SecurityPrincipalEntity ");
}
@Override
protected SecurityPrincipalEntity fetchByKeyFromDb(Long key) throws PersistException {
return (SecurityPrincipalEntity) Persist.session(getType())
.get(SecurityPrincipalEntity.class, key);
}
@Override
protected Query getFetchBatchQuery() {
return Persist.session(getType())
.createQuery("select c from SecurityPrincipalEntity c order by c.key");
}
@Override
protected Query getFetchAllQuery() throws PersistException {
return Persist.session(getType()).createQuery("select e from SecurityPrincipalEntity e");
}
@Override
protected Query getCountAllEntitiesQuery() {
return Persist.session(getType())
.createQuery("select count(c) from SecurityPrincipalEntity c");
}
@Override
protected Class<?>[] getTypes() {
return new Class<?>[]{SecurityPrincipalEntity.class};
}
@Override
protected Query deleteEntityByKeyQuery() {
return Persist.session(getType())
.createQuery("delete from SecurityPrincipalEntity r where r.key = ?");
}
@Override
protected String getPersistName() {
return "principal";
}
}
END SUBMISSION
END SUBMISSION
END SUBMISSION