gpt4 book ai didi

java - Hibernate Java 持久化列问题

转载 作者:行者123 更新时间:2023-12-01 05:43:26 25 4
gpt4 key购买 nike

我不断收到此错误,但找不到解决方法。无法确定类型: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>

提前致谢!

最佳答案

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

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

关于java - Hibernate Java 持久化列问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6516077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com