- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试通过从域对象创建表来测试一对多映射,但我看到错误mappedBy 引用未知的目标实体属性。有人可以看一下吗?
谢谢
员工.java
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;
}
}
FulltimeEmployee.java
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;
}
}
ContractEmployee.java
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;
}
}
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;
}
}
员工状态
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();
}
}
错误堆栈跟踪
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)
感谢您的回复。我做了您提到的更改,还做了一些其他更改,例如将 session.save(flightBenefit) 添加到 Main.java 和 insertable = false, updatable = false with @JoinColumn注解。我看到正在创建 Employee 表但没有创建 FlightBenefit 并且看到了错误
引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'TestSchema.flightbenefit'不存在
以下是具有更新更改和堆栈跟踪的类
主.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();
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();
}
}
FulltimeEmployee.Java
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
最佳答案
原始问题的答案:
以下是不正确的,因为 FulltimeEmployee
没有名为 FlightBenefit
的持久属性
@OneToMany(mappedBy = "FlightBenefit")
private Set<FulltimeEmployee> FulltimeEmployees;
持久属性的名称区分大小写。因为属性是flightBenefit
(第一个字符是小写),所以在mappedBy中使用时名称应该完全相同:
@OneToMany(mappedBy = "flightBenefit")
此外,如警告所述,在子类中使用表注释对 SINGLE_TABLE 没有意义:它们被持久化到单个表,因此表是相同的。
修改后的问题答案:
现在问题来自:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private String id;
那行不通,因为字符串(数据库中的 varchar)没有自动递增。日志中的以下消息也说明了这一点:列“id”的列说明符不正确。在可行的情况下,改用 Integer/Long。
关于database - Hibernate一对多映射错误-mappedBy reference an unknown target entity property错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16871012/
这是我的代码 14 20 {"Confirm Email"} 21 在第 17 行我得到错误 Type '{ pathname: string; user: { em
这是我的代码 14 20 {"Confirm Email"} 21 在第 17 行我得到错误 Type '{ pathname: string; user: { em
这个问题已经有答案了: How do I compare strings in Java? (23 个回答) 已关闭 8 年前。 为什么 KeyEvent.getKeyText(0).substrin
我正在尝试 Rust 的新 wasm32-unknown-unknown 目标,我在调用数学函数(例如 sin、cos、exp、atan2)时遇到问题。 cargo .toml: [package]
当我为 spring-boot 创建启动项目时,我在 pom 文件中收到此错误。这只是为了创建一个基本的 Spring Boot 项目 Project build error: Invalid pac
我已经订阅了我想要传输的数据。但不知何故它不起作用。我收到此错误: The property pipe is not available for type "OperatorFunction" 这是我
运行以下查询时。select * from surgerys where to_char(dt_surgery ,'DD-MM-YYYY' ) = to_char('12-02-2012','DD-M
我在运行存储过程时遇到以下异常: com.microsoft.sqlserver.jdbc.SQLServerException:不支持从 UNKNOWN 到 UNKNOWN 的转换。 过程定义如下:
我尝试运行以下代码。顺便说一句,我对 python 和 sklearn 都是新手。 import pandas as pd import numpy as np from sklearn.linear
我已经阅读了关于未知类型的官方文档,但我很难真正理解它是如何工作的。 人们可以在文档中读到:“在没有首先断言或缩小到更具体的类型之前,不允许对未知进行任何操作。” 但如果我有这个功能: const f
我正在尝试在Mac OS中设置Hadoop 2.6.0 我正在关注这篇文章: http://hadoop.apache.org/docs/r2.4.0/hadoop-project-dist/hado
配置 Nexus docker 注册表和代理“dockerhub-proxy”后,如下所述: https://help.sonatype.com/repomanager3/formats/docker
我收到此错误 - “ValueError:未知标签类型:'unknown'” 我已经在网上搜索但无法摆脱这个错误,顺便说一句,我是 python 的新手:) 我的数据有 5 行 22 列,最后一列是标
使用 SHA256 摘要标识符 拉取图像失败 最佳答案 不幸的是,这是 DockerHub 删除 Docker 1.9 守护进程的向后兼容性的副作用。当使用 Docker 1.10 推送图像时,较旧的
我是 postgresql 的新手,正在尝试使用全文搜索 to_tsvector但是我遇到了错误。 SQL 和错误 SELECT to_tsvector('english', 'The quick b
每当我这样做时 npm run watch ,第一次编译工作正常 - 但经过几次编译后,我最终会得到这个错误: 95% emitting unnamed compat pluginError: UNK
在一个新的 Angular 应用程序中,我收到以下错误:Error from chokidar : Error: UNKNOWN: unknown error, watch我已经删除并重新安装 nod
使用 Typescipt 4.x.x 我写了一些代码来实现其他语言 Elm/Rust/Haskell 中常用的 Maybe/Option 类型。 我想写一个可以接受映射类型的通用函数 type MyM
const submitted = useSelector((state) => state.post.submitted) 对于上面的状态。我得到错误: (参数)状态:未知对象的类型为“未知”。 这
我正在尝试将多架构 docker 镜像推送到 docker hub 并遇到错误(在 https://github.com/docker/distribution/issues/3100 处打开了 do
我是一名优秀的程序员,十分优秀!