找不到Hibernate Mapping异常类

时间:2015-07-13 13:40:17

标签: java hibernate

我在这个关于hibernate映射的问题上工作了几个小时。我认为错误可能是一个简单的语法错误,但我找不到它!

我执行代码时遇到了以下异常:

Initial SessionFactory creation failed.org.hibernate.MappingException: entity class not found: LegalFee
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.plm.dao.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:33)
    at com.plm.dao.util.HibernateUtil.getSessionFactory(HibernateUtil.java:39)
    at com.plm.dao.AppTest.main(AppTest.java:15)

首先,我正在使用带有Java 8和MariaDB 10的hibernate 4.2。

请参阅以下所有配置。

我的hibernate.cfg.xml,我删除了C3P0配置:

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name='connection.driver_class'>com.mysql.jdbc.Driver</property>
        <property name='connection.url'>jdbc:mysql://localhost:3306/PokerLeagueManager</property>
        <property name='connection.username'>root</property>
        <property name='connection.password'>mypassword</property>
        <property name="show_sql">true</property>

        <!-- SQL dialect -->
        <property name='dialect'>org.hibernate.dialect.MySQL5InnoDBDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
        <!-- Disable the second-level cache -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>


        <!-- Echo all executed SQL to stdout -->
        <property name='show_sql'>true</property>

        <mapping resource="mappings/BlindStructure.hbm.xml"/>
        <mapping resource="mappings/Tournament.hbm.xml"/>
        <mapping resource="mappings/LegalFee.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

错误在LegalFee bean上,所以请关注它。 请参阅legalFee的sql表创建:

CREATE TABLE `legalFee` (
  `idFee` int(11) NOT NULL,
  `shortName` varchar(50) NOT NULL,
  `description` varchar(200) DEFAULT NULL,
  `feePercent` int(11) DEFAULT NULL,
  `feeFixed` int(11) DEFAULT NULL,
  PRIMARY KEY (`idFee`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

班级:

public class LegalFee implements Serializable {

/**
 * generated serial uid
 */
private static final long serialVersionUID = -2259355205530727294L;

private int idFee;
private String shortName;
private String description;
private Integer feePercent;
private Integer feeFixed;
private Set<Tournament> tournaments = new HashSet<Tournament>(0);

public LegalFee() {
}

public LegalFee(int idFee, String shortName) {
    this.idFee = idFee;
    this.shortName = shortName;
}

public LegalFee(int idFee, String shortName, String description,
        Integer feePercent, Integer feeFixed, Set<Tournament> tournaments) {
    this.idFee = idFee;
    this.shortName = shortName;
    this.description = description;
    this.feePercent = feePercent;
    this.feeFixed = feeFixed;
    this.tournaments = tournaments;
}

public int getIdFee() {
    return this.idFee;
}

public void setIdFee(int idFee) {
    this.idFee = idFee;
}

public String getShortName() {
    return this.shortName;
}

public void setShortName(String shortName) {
    this.shortName = shortName;
}

public String getDescription() {
    return this.description;
}

public void setDescription(String description) {
    this.description = description;
}

public Integer getFeePercent() {
    return this.feePercent;
}

public void setFeePercent(Integer feePercent) {
    this.feePercent = feePercent;
}

public Integer getFeeFixed() {
    return this.feeFixed;
}

public void setFeeFixed(Integer feeFixed) {
    this.feeFixed = feeFixed;
}

public Set<Tournament> getTournaments() {
    return this.tournaments;
}

public void setTournaments(Set<Tournament> tournaments) {
    this.tournaments = tournaments;
}

}

最后是LegalFee.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

 <hibernate-mapping>
    <class name="LegalFee" table="legalFee" catalog="PokerLeagueManager" optimistic-lock="version">
        <id name="idFee" type="int">
            <column name="idFee" />
            <generator class="identity" />
        </id>
        <property name="shortName" type="string">
            <column name="shortName" length="50" not-null="true" />
        </property>
        <property name="description" type="string">
            <column name="description" length="200" />
        </property>
        <property name="feePercent" type="java.lang.Integer">
            <column name="feePercent" />
        </property>
        <property name="feeFixed" type="java.lang.Integer">
            <column name="feeFixed" />
        </property>
        <set name="tournaments" table="tournament" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="legalFee_feeId" />
            </key>
            <one-to-many class="Tournament" />
        </set>
    </class>
</hibernate-mapping>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

如果您的LegalFee类不在默认包中,则需要提供该类的完全分类名称。 例如&#34; class name =&#34; com.abc.xyx.LegalFee&#34;表=&#34; legalFee&#34; &#34;