Java 为什么';这个设置是否适用于JPA和Hibernate中的外键关系?
我正在尝试使用注释设置外键关系,并使用生成表,但我遇到了一个错误,看不出原因。我在User中执行main方法来生成表 这是错误-Java 为什么';这个设置是否适用于JPA和Hibernate中的外键关系?,java,hibernate,jpa,Java,Hibernate,Jpa,我正在尝试使用注释设置外键关系,并使用生成表,但我遇到了一个错误,看不出原因。我在User中执行main方法来生成表 这是错误- INFO: Hibernate Validator not found: ignoring Exception in thread "main" org.hibernate.MappingException: Could not determine type for: com.site.model.Name, at table: USER, for column
INFO: Hibernate Validator not found: ignoring
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: com.site.model.Name, at table: USER, for columns: [org.hibernate.mapping.Column(name)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306)
at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:164)
at org.hibernate.mapping.Column.getSqlType(Column.java:208)
at org.hibernate.mapping.Table.sqlCreateString(Table.java:418)
at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:1099)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:131)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)
at com.thepoliticalbottomline.model.User.main(User.java:55)
类名
package com.sitename.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Name {
private Long id;
private String first;
private String middle;
private String last;
/**
* @return the id
*/
@Id
@GeneratedValue
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the first
*/
public String getFirst() {
return first;
}
/**
* @param first the first to set
*/
public void setFirst(String first) {
this.first = first;
}
/**
* @return the middle
*/
public String getMiddle() {
return middle;
}
/**
* @param middle the middle to set
*/
public void setMiddle(String middle) {
this.middle = middle;
}
/**
* @return the last
*/
public String getLast() {
return last;
}
/**
* @param last the last to set
*/
public void setLast(String last) {
this.last = last;
}
}
不能在属性和方法上混合使用JPA注释。只能对给定类中的属性或方法进行注释 这适用于Hibernate。我不确定其他JPA实现
package com.sitename.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Name {
private Long id;
private String first;
private String middle;
private String last;
/**
* @return the id
*/
@Id
@GeneratedValue
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the first
*/
public String getFirst() {
return first;
}
/**
* @param first the first to set
*/
public void setFirst(String first) {
this.first = first;
}
/**
* @return the middle
*/
public String getMiddle() {
return middle;
}
/**
* @param middle the middle to set
*/
public void setMiddle(String middle) {
this.middle = middle;
}
/**
* @return the last
*/
public String getLast() {
return last;
}
/**
* @param last the last to set
*/
public void setLast(String last) {
this.last = last;
}
}