当前位置: 首页 > 知识库问答 >
问题:

Hibernate一对多映射错误-mappedBy引用未知目标实体属性错误

戚弘和
2023-03-14

我试图通过从域对象创建表来测试一对多映射,但我看到错误mappedBy引用未知的目标实体属性。谁能看一下吗?

谢谢

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;  
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;


@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "employeetype", discriminatorType    
=DiscriminatorType.STRING)
@Table(name = "Employee")
public abstract class Employee {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private int id;

@Column(name = "name")
private String name;

@Enumerated(EnumType.STRING)
@Column(name = "status")
private EmployeeStatus status;

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "hireDate")
private DateTime hireDate;

/**
 * @return the hireDate
 */
public DateTime getHireDate() {
    return hireDate;
}

/**
 * @return the id
 */
public int getId() {
    return id;
}

/**
 * @return the name
 */
public String getName() {
    return name;
}

/**
 * @return the Status
 */
public EmployeeStatus getStatus() {
    return status;
}

/**
 * @param hireDate
 *            the hireDate to set
 */
public void setHireDate(final DateTime hireDate) {
    this.hireDate = hireDate;
}

/**
 * @param id
 *            the id to set
 */
public void setId(final int id) {
    this.id = id;
}

/**
 * @param name
 *            the name to set
 */
public void setName(final String name) {
    this.name = name;
}

/**
 * @param status
 *            the status to set
 */
public void setStatus(final EmployeeStatus status) {
    this.status = status;
}

}
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@DiscriminatorValue("FulltimeEmployee")
@Table(name = "FulltimeEmployee")
public class FulltimeEmployee extends Employee {

@Column(name = "cubeNumber")
private String cubeNumber;

@ManyToOne
@JoinColumn(name = "id")
private FlightBenefit flightBenefit;

/**
 * @return the cubeNumber
 */
public String getCubeNumber() {
    return cubeNumber;
}

/**
 * @return the flightBenefit
 */
public FlightBenefit getFlightBenefit() {
    return flightBenefit;
}

/**
 * @param cubeNumber
 *            the cubeNumber to set
 */
public void setCubeNumber(final String cubeNumber) {
    this.cubeNumber = cubeNumber;
}

/**
 * @param flightBenefit
 *            the flightBenefit to set
 */
public void setFlightBenefit(final FlightBenefit flightBenefit) {
    this.flightBenefit = flightBenefit;
}

}
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Table;


@Entity
@DiscriminatorValue("ContractEmployee")
@Table(name = "ContractEmployee")
public class ContractEmployee extends Employee {

@Column(name = "openAreaNumber")
private String openAreaNumber;

/**
 * @return the openAreaNumber
 */
public String getOpenAreaNumber() {
    return openAreaNumber;
}

/**
 * @param openAreaNumber
 *            the openAreaNumber to set
 */
public void setOpenAreaNumber(final String openAreaNumber) {
    this.openAreaNumber = openAreaNumber;
}

}
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;


@Entity
@Table(name = "FlightBenefit")
public class FlightBenefit {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private String id;

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "useByTime")
private DateTime useByTime;

@Column(name = "discountAmount")
private String discountAmount;

@OneToMany(mappedBy = "FlightBenefit")
private Set<FulltimeEmployee> FulltimeEmployees;

/**
 * @return the discountAmount
 */
public String getDiscountAmount() {
    return discountAmount;
}

/**
 * @return the fulltimeEmployees
 */
public Set<FulltimeEmployee> getFulltimeEmployees() {
    return FulltimeEmployees;
}

/**
 * @return the id
 */
public String getId() {
    return id;
}

/**
 * @return the useByTime
 */
public DateTime getUseByTime() {
    return useByTime;
}

/**
 * @param discountAmount
 *            the discountAmount to set
 */
public void setDiscountAmount(final String discountAmount) {
    this.discountAmount = discountAmount;
}

/**
 * @param fulltimeEmployees
 *            the fulltimeEmployees to set
 */
public void setFulltimeEmployees(final Set<FulltimeEmployee> fulltimeEmployees) {
    FulltimeEmployees = fulltimeEmployees;
}

/**
 * @param id
 *            the id to set
 */
public void setId(final String id) {
    this.id = id;
}

/**
 * @param useByTime
 *            the useByTime to set
 */
public void setUseByTime(final DateTime useByTime) {
    this.useByTime = useByTime;
}

}
public enum EmployeeStatus {

ACTIVE,

INACTIVE

}

hibernate.cfg.xml

?xml version="1.0" encoding="UTF-8"?
 !DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"
hibernate-configuration
 session-factory
property name="connection.driver_class">com.mysql.jdbc.Driver</property
property    
name="connection.url">jdbc:mysql://localhost:3306/TestDB</property
property name="connection.username">user</property
property name="connection.password">password123</property
property name="show_sql">true</property
property name="dialect">org.hibernate.dialect.MySQLDialect</property
property name="hibernate.default_schema">TestSchema</property
!--    <property name="hbm2ddl.auto">validate</property> --
/session-factory&
/hibernate-configuration&


**Main.java**



import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.joda.time.DateTime;


public class Main {

public static void main(final String args[]) {

    Configuration config = new Configuration();
    config.addAnnotatedClass(ContractEmployee.class);
    config.addAnnotatedClass(FulltimeEmployee.class);
    config.addAnnotatedClass(FlightBenefit.class);

    config.configure("hibernate.cfg.xml");

    SchemaExport se = new SchemaExport(config);
    se.execute(true, true, false, true);

    SessionFactory factory = config.buildSessionFactory();

    Session session = factory.openSession();
    session.beginTransaction();

    ContractEmployee cEmployee = new ContractEmployee();
    cEmployee.setName("Raj");
    cEmployee.setStatus(EmployeeStatus.ACTIVE);
    cEmployee.setHireDate(DateTime.now());
    cEmployee.setOpenAreaNumber("421a29");
    session.save(cEmployee);

    FlightBenefit flightbenefit = new FlightBenefit();
    flightbenefit.setDiscountAmount("1000");
    flightbenefit.setUseByTime(DateTime.now());

    FulltimeEmployee fEmployee = new FulltimeEmployee();
    fEmployee.setName("Teja");
    fEmployee.setStatus(EmployeeStatus.INACTIVE);
    fEmployee.setHireDate(DateTime.now());
    fEmployee.setCubeNumber("Cube 19");
    fEmployee.setFlightBenefit(flightbenefit);
    session.save(fEmployee);

    session.flush();
    session.getTransaction().commit();
    session.close();

}
}

错误StackTrace

Jun 1, 2013 2:21:14 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jun 1, 2013 2:21:14 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.2.Final}
Jun 1, 2013 2:21:14 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jun 1, 2013 2:21:14 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jun 1, 2013 2:21:14 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
Jun 1, 2013 2:21:14 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate.cfg.xml
Jun 1, 2013 2:21:14 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jun 1, 2013 2:21:14 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jun 1, 2013 2:21:15 AM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy:     
ContractEmployee
Jun 1, 2013 2:21:15 AM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy:    
FulltimeEmployee
Exception in thread "main" org.hibernate.AnnotationException: mappedBy reference an     
unknown target entity property: FulltimeEmployee.FlightBenefit in   
FlightBenefit.FulltimeEmployees at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:708)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:69)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1611)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1369)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:941)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:188)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:156)
at Main.main(Main.java:23)

谢谢你的回复。我做了您提到的更改,还做了一些其他更改,比如向main.java添加session.save(flightvenive)和insertable=false,updatable=false以及@JoinColumn注释。我看到正在创建Employee表,但没有创建FlightBenefity,并看到错误

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.joda.time.DateTime;


public class Main {

public static void main(final String args[]) {

    Configuration config = new Configuration();
    config.addAnnotatedClass(ContractEmployee.class);
    config.addAnnotatedClass(FulltimeEmployee.class);
    config.addAnnotatedClass(FlightBenefit.class);
    config.configure("hibernate.cfg.xml");

    SchemaExport se = new SchemaExport(config);
    se.execute(true, true, false, true);

    SessionFactory factory = config.buildSessionFactory();

    Session session = factory.openSession();
    session.beginTransaction();

    FlightBenefit flightbenefit = new FlightBenefit();
    flightbenefit.setDiscountAmount("1000");
    flightbenefit.setUseByTime(DateTime.now());
    session.save(flightbenefit);

    ContractEmployee cEmployee = new ContractEmployee();
    cEmployee.setName("Raj");
    cEmployee.setStatus(EmployeeStatus.ACTIVE);
    cEmployee.setHireDate(DateTime.now());
    cEmployee.setOpenAreaNumber("421a29");
    session.save(cEmployee);



    FulltimeEmployee fEmployee = new FulltimeEmployee();
    fEmployee.setName("Teja");
    fEmployee.setStatus(EmployeeStatus.INACTIVE);
    fEmployee.setHireDate(DateTime.now());
    fEmployee.setCubeNumber("Cube 19");
    fEmployee.setFlightBenefit(flightbenefit);
    session.save(fEmployee);

    session.flush();
    session.getTransaction().commit();
    session.close();

}
}
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;


@Entity
@DiscriminatorValue("FulltimeEmployee")
public class FulltimeEmployee extends Employee {

@Column(name = "cubeNumber")
private String cubeNumber;

@ManyToOne
@JoinColumn(name = "id", insertable =  false, updatable = false)
private FlightBenefit flightBenefit;

/**
 * @return the cubeNumber
 */
public String getCubeNumber() {
    return cubeNumber;
}

/**
 * @return the flightBenefit
 */
public FlightBenefit getFlightBenefit() {
    return flightBenefit;
}

/**
 * @param cubeNumber
 *            the cubeNumber to set
 */
public void setCubeNumber(final String cubeNumber) {
    this.cubeNumber = cubeNumber;
}

/**
 * @param flightBenefit
 *            the flightBenefit to set
 */
public void setFlightBenefit(final FlightBenefit flightBenefit) {
    this.flightBenefit = flightBenefit;
}

}

flightBenefit.java

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;


@Entity
@Table(name = "FlightBenefit")
public class FlightBenefit {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private String id;

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "useByTime")
private DateTime useByTime;

@Column(name = "discountAmount")
private String discountAmount;

@OneToMany(mappedBy = "flightBenefit")
private Set<FulltimeEmployee> FulltimeEmployees;

/**
 * @return the discountAmount
 */
public String getDiscountAmount() {
    return discountAmount;
}

/**
 * @return the fulltimeEmployees
 */
public Set<FulltimeEmployee> getFulltimeEmployees() {
    return FulltimeEmployees;
}

/**
 * @return the id
 */
public String getId() {
    return id;
}

/**
 * @return the useByTime
 */
public DateTime getUseByTime() {
    return useByTime;
}

/**
 * @param discountAmount
 *            the discountAmount to set
 */
public void setDiscountAmount(final String discountAmount) {
    this.discountAmount = discountAmount;
}

/**
 * @param fulltimeEmployees
 *            the fulltimeEmployees to set
 */
public void setFulltimeEmployees(final Set<FulltimeEmployee> fulltimeEmployees) {
    FulltimeEmployees = fulltimeEmployees;
}

/**
 * @param id
 *            the id to set
 */
public void setId(final String id) {
    this.id = id;
}

/**
 * @param useByTime
 *            the useByTime to set
 */
public void setUseByTime(final DateTime useByTime) {
    this.useByTime = useByTime;
}

}

斯塔克特莱斯

Jun 1, 2013 2:18:18 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jun 1, 2013 2:18:18 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.2.Final}
Jun 1, 2013 2:18:18 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jun 1, 2013 2:18:18 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jun 1, 2013 2:18:18 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
Jun 1, 2013 2:18:18 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate.cfg.xml
Jun 1, 2013 2:18:19 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jun 1, 2013 2:18:19 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jun 1, 2013 2:18:21 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Jun 1, 2013 2:18:21 PM     
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl   
configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jun 1, 2013 2:18:21 PM 
 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl 
 configure
INFO: HHH000115: Hibernate connection pool size: 20
Jun 1, 2013 2:18:21 PM     
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl   
 configure
INFO: HHH000006: Autocommit mode: false
Jun 1, 2013 2:18:21 PM  
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl 
configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL    
[jdbc:mysql://localhost:3306/TestSchema]
Jun 1, 2013 2:18:21 PM   
 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl   
 configure
INFO: HHH000046: Connection properties: {user=user, password=****}

create table TestSchema.Employee (
    employeetype varchar(31) not null,
    id integer not null auto_increment,
    hireDate datetime,
    name varchar(255),
    status varchar(255),
    openAreaNumber varchar(255),
    cubeNumber varchar(255),
    primary key (id)
)

create table TestSchema.FlightBenefit (
    id varchar(255) not null auto_increment,
    discountAmount varchar(255),
    useByTime datetime,
    primary key (id)
)
Jun 1, 2013 2:18:23 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table TestSchema.FlightBenefit (id varchar(255)     
not null auto_increment, discountAmount varchar(255), useByTime datetime, primary key  
(id))
Jun 1, 2013 2:18:23 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: Incorrect column specifier for column 'id'

alter table TestSchema.Employee 
    add index FK_opia9u461cgfe5i9vk7bo0p56 (id), 
    add constraint FK_opia9u461cgfe5i9vk7bo0p56 
    foreign key (id) 
    references TestSchema.FlightBenefit (id)
Jun 1, 2013 2:18:23 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: alter table TestSchema.Employee add index   
FK_opia9u461cgfe5i9vk7bo0p56 (id), add constraint FK_opia9u461cgfe5i9vk7bo0p56 foreign   
 key (id) references TestSchema.FlightBenefit (id)
Jun 1, 2013 2:18:23 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: Cannot add foreign key constraint
Jun 1, 2013 2:18:23 PM   
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl  
stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/TestSchema]
Jun 1, 2013 2:18:23 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Jun 1, 2013 2:18:23 PM   
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl 
configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)

Jun 1, 2013 2:18:23 PM  

org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl 
 configure
INFO: HHH000115: Hibernate connection pool size: 20
Jun 1, 2013 2:18:23 PM     
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl 
configure

 INFO: HHH000006: Autocommit mode: false
 Jun 1, 2013 2:18:23 PM   
 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl  
 configure
 INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL    
[jdbc:mysql://localhost:3306/TestSchema]
Jun 1, 2013 2:18:23 PM  
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl 
configure
INFO: HHH000046: Connection properties: {user=user, password=****}
Jun 1, 2013 2:18:23 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jun 1, 2013 2:18:23 PM   
org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Jun 1, 2013 2:18:23 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: insert into TestSchema.FlightBenefit (discountAmount, useByTime) values (?,   
?)
Jun 1, 2013 2:18:25 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
Jun 1, 2013 2:18:25 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'TestSchema.flightbenefit' doesn't exist
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not    
execute statement
at 
    org.hibernate.exception.internal.SQLExceptionTypeDelegate.
    convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.
    convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.
   convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.
   convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.   
     executeUpdate(ResultSetReturnImpl.java:136)
at 
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.
executeAndExtract(IdentityGenerator.java:96)
at org.hibernate.id.insert.AbstractReturningDelegate.
 performInsert(AbstractReturningDelegate.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.
 insert(AbstractEntityPersister.java:2975)
at org.hibernate.persister.entity.AbstractEntityPersister.
  insert(AbstractEntityPersister.java:3487)
at org.hibernate.action.internal.EntityIdentityInsertAction.
  execute(EntityIdentityInsertAction.java:81)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
at org.hibernate.engine.spi.ActionQueue.
     addResolvedEntityInsertAction(ActionQueue.java:214)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:194)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:178)
at org.hibernate.event.internal.AbstractSaveEventListener.
   addInsertAction(AbstractSaveEventListener.java:321)
at org.hibernate.event.internal.AbstractSaveEventListener.
   performSaveOrReplicate(AbstractSaveEventListener.java:286)
at org.hibernate.event.internal.AbstractSaveEventListener.
      performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.
      saveWithGeneratedId(AbstractSaveEventListener.java:125)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.
     saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveEventListener.
  saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.
  entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveEventListener.
   performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.
   onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:764)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:756)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:752)
at Main.main(Main.java:34)
   Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table     
 'TestSchema.flightbenefit' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at   

 org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.
 executeUpdate(ResultSetReturnImpl.java:133)
... 22 more

共有1个答案

方和宜
2023-03-14

原问题答案:

以下内容不正确,因为FullTimeEmployee没有名为FlightVelive的持久属性

@OneToMany(mappedBy = "FlightBenefit")
private Set<FulltimeEmployee> FulltimeEmployees;

持久性属性的名称区分大小写。因为属性是flightvelive(第一个字符是小写),所以在MappedBy中使用name时应该完全相同:

@OneToMany(mappedBy = "flightBenefit")
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private String id;

这不起作用,因为字符串(数据库中的varchar)没有自动递增。这也在以下消息的日志中被告知:列'id'的列说明符不正确。可行时,改用整数/长。

 类似资料:
  • 首先,我的课程: 使用者 角色地图。JAVA 当我尝试在服务器上运行这个我有这样的异常:错误创建bean与名称'SessionFactory'定义在ServletContext资源[/WEB-INF/类/base Beans.xml]:调用init方法失败;嵌套的异常org.hibernate.注释异常:映射通过引用一个未知的目标实体属性:com.patpuc.model.ap.users在com

  • 我正在做一个测试项目来学习Hibernate,不幸的是,我得到了这个错误,并查看了其他类似的错误,但是遵循它们并没有解决我的问题。我仍然得到这个错误。 如果有人能检查出哪里出了问题,我真的很想知道我的错误是什么。 我的模型类: } 这是第二个模型类: } 这是我的主要: 这是我的hibernate util类: 公共类HibernateUtil{私有静态最终会议工厂会议工厂=构建会议工厂(); }

  • 尽管已经讨论了这个错误,但我不知道如何解决我的问题。我读到这个问题可能会被映射,所以我尝试了不同的选择,但问题仍然存在 控制台: Model.java: Article.java

  • 我第一次使用Hibernate,并且很难让它与我的模式一起工作。 我得到了"org.hibernate.注释异常:映射通过引用未知的目标实体属性:学生。教师在Faculty.all学生”。 一些学生共用一个导师。因此,我认为学生和教师的关系是多对多的,但我被告知这是多对多的关系。 Student.java Faculty.java 数据库架构: 在看了留档后,我尝试了几种不同的注释,但我看不出我做

  • 我有几个从db动态创建的实体类,但是当我用关系注释它们时,我有以下错误 组织。冬眠AnnotationException:mappedBy引用未知的目标实体属性:coma。实体impl。能力标准实施。昏迷中的能力。实体impl。胜任力impl。能力标准执行 我的实体类如下 和 我对冬眠感到困惑和绝望。。。

  • 我的模型由不同类型的预算组成。这些预算具有不同的属性。我想在这些不同类型的预算之间建立一种“一对一”的关系。假设我有一个BudgetLevel1,它有很多BudgetLevel2,它也有很多BucketLevel3。所有这些BudgetLevel扩展了类预算 我的预算课程 预算级别1类 预算级别2类 预算级别3 看起来类似 这是我得到的错误 org.springframework.beans.fa