持久化列的Hibernate Java问题

时间:2011-06-29 05:19:51

标签: java hibernate persistence

我一直收到此错误,但无法找到解决方法。 无法确定类型:org.digitalcorpse.pirates.Pirate,对于列:[org.hibernate.mapping.Column(pirate)]

package org.digitalcorpse.pirates;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;

@Entity
public class Pirate {
    @Id
    @GeneratedValue
    private String login;
    private String password;
    private String name;
    private int skillSailing;
    private int skillCannons;
    private int skillMaps;
    private int skillLeadership;
    private int skillFixing;
    private float gold;
    private int karma;
    @OneToOne
    private Parrot parrot;
    @OneToOne
    private Fleet fleet;

    public Pirate() {
    }

    public Pirate(String login, String password) {
        this.login = login;
        this.password = password;
    }

    public Fleet getFleet() {
        return fleet;
    }

    public void setFleet(Fleet fleet) {
        this.fleet = fleet;
    }

    public float getGold() {
        return gold;
    }

    public void setGold(float gold) {
        this.gold = gold;
    }

    public int getKarma() {
        return karma;
    }

    public void setKarma(int karma) {
        this.karma = karma;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Parrot getParrot() {
        return parrot;
    }

    public void setParrot(Parrot parrot) {
        this.parrot = parrot;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getSkillCannons() {
        return skillCannons;
    }

    public void setSkillCannons(int skillCannons) {
        this.skillCannons = skillCannons;
    }

    public int getSkillFixing() {
        return skillFixing;
    }

    public void setSkillFixing(int skillFixing) {
        this.skillFixing = skillFixing;
    }

    public int getSkillLeadership() {
        return skillLeadership;
    }

    public void setSkillLeadership(int skillLeadership) {
        this.skillLeadership = skillLeadership;
    }

    public int getSkillMaps() {
        return skillMaps;
    }

    public void setSkillMaps(int skillMaps) {
        this.skillMaps = skillMaps;
    }

    public int getSkillSailing() {
        return skillSailing;
    }

    public void setSkillSailing(int skillSailing) {
        this.skillSailing = skillSailing;
    }


}

我的持久单位

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="piratesPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>org.digitalcorpse.pirates.Battle</class>
    <class>org.digitalcorpse.pirates.Fleet</class>
    <class>org.digitalcorpse.pirates.Looting</class>
    <class>org.digitalcorpse.pirates.Parrot</class>
    <class>org.digitalcorpse.pirates.Pirate</class>
    <class>org.digitalcorpse.pirates.Ship</class>
    <class>org.digitalcorpse.pirates.Store</class>
    <class>org.digitalcorpse.pirates.TreasureHunt</class>
    <properties>
      <property name="hibernate.connection.username" value="piratesPU"/>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
      <property name="hibernate.connection.password" value="pirates"/>
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/piratesPU"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

提前致谢!

1 个答案:

答案 0 :(得分:0)

您应该像这样为表和列添加映射 @Table(name =“my_pirate_table”)

@Column(name="fleet_column_in_your_table_name", nullable=false)
public Fleet getFleet() {        
  return fleet;    
}