hibernate migration 3.5 to 4.3.5未知实体错误

时间:2014-10-07 15:59:35

标签: hibernate migration mapping

直接从3.5(特别是hibernate3.jar)迁移到4.3.5。应用程序是使用基本JAXB(@XMLRootElement等)注释的简单POJO。另外,简单的hbm.xml和cfg.xml。由不起眼的持久性类用于PostgreSQL数据库。操作系统是Fedora20。修复了编译错误,例如hibernate.org DTD位置。

所有表的错误是“未知实体”。我需要说,“它看起来应该有效,但不是。”会很感激。提前谢谢了。 -MB

Hibernate .jar文件增量(在类路径中):

PREVIOUS:

  • antlr-2.7.6.jar
  • c3p0-0.9.1.jar
  • cglib-2.2.jar
  • commons-collections-3.1.jar
  • dom4j-1.6.1.jar
  • hibernate-jpa-2.0-api-1.0.0.Final.jar
  • hibernate-validator-4.0.2.GA.jar
  • hibernate3.jar
  • javassist-3.9.0.GA.jar
  • jta-1.1.jar oscache-2.1.jar
  • proxool-0.8.3.jar
  • slf4j-api-1.5.11.jar
  • slf4j-log4j12-1.5.11.jar
  • swarmcache-1.0RC2.jar

NEW:

  • ANTLR-2.7.7.jar
  • c3p0-0.9.2.1.jar
  • hibernate-c3p0-4.3.5.Final.jar
  • mchange-commons-java-0.2.3.4.jar
  • commons-collections4-4.0.jar
  • hibernate-commons-annotations-4.0.4.Final
  • hibernate-core-4.3.5.Final.jar
  • jandex-1.1.0.Final.jar
  • jboss-logging-3.1.3.GA.jar
  • jboss-logging-annotations-1.2.0.Beta1.jar
  • jboss-transaction-api_1.2_spec-1.0.0.Final.jar
  • hibernate-envers-4.3.5.Final.jar
  • hibernate-entitymanager-4.3.5.Final.jar
  • dom4j-1.6.1.jar
  • hibernate-jpa-2.1-api-1.0.0.Final.jar
  • hibernate / hibernate-validator-5.1.1.Final.jar
  • hibernate-testing-4.3.5.Final.jar
  • jbosscache-core.jar jboss-cache.jar
  • ehcache-core-2.4.3.jar
  • hibernate-ehcache-4.3.5.Final.jar
  • hibernate-infinispan-4.3.5.Final.jar
  • infinispan-commons-6.0.0.Final.jar
  • infinispan-core-6.0.0.Final.jar
  • javassist-3.18.1-GA.jar
  • jta-1.1.jar oscache-2.4.1.jar

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

0 个答案:

没有答案