我无法从实体生成表。我在Mac OSX上使用Eclipse Photon,已成功与本地PostgreSQL数据库建立连接并成功测试了正确的ping。
现在,问题是当我单击“ JPA工具->从实体生成表”时,Eclipse没有执行任何操作。没有这样的错误消息,没有这样的信号。
我已经映射了我的实体,下面附上一些示例。
AccessDataEntity.java
@Entity
@Table(name = "access_data")
public class AccessDataEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@Column(name = "password", length = 15)
private String password;
@OneToOne
private PersonalInformationEntity personalInformation;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public PersonalInformationEntity getPersonalInformation() {
return personalInformation;
}
public void setPersonalInformation(PersonalInformationEntity personalInformation) {
this.personalInformation = personalInformation;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
PersonalInformationEntity.java
@Entity
@Table(name = "personal_information")
public class PersonalInformationEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id")
private long id;
@Column(name = "name", length = 30)
private String name;
@Column(name = "surname", length = 30)
private String surname;
@Column(name = "email", length = 20)
private String email;
@Column(name = "date_of_birth")
private Date dateOfBirth;
@OneToOne(mappedBy = "personalInformation", cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
private AccountEntity account;
@OneToMany(mappedBy = "personalInformation", fetch = FetchType.LAZY)
private List<PersonalGoalEntity> personalGoals;
@OneToOne(mappedBy = "personalInformation", fetch = FetchType.LAZY)
private AccessDataEntity accessData;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public AccountEntity getAccount() {
return account;
}
public void setAccount(AccountEntity account) {
this.account = account;
}
public List<PersonalGoalEntity> getPersonalGoals() {
return personalGoals;
}
public void setPersonalGoals(List<PersonalGoalEntity> personalGoals) {
this.personalGoals = personalGoals;
}
}
我还配置了 persistence.xml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="aster.jpa">
<class>it.manuelgozzi.aster.jpa.entity.AccessDataEntity</class>
<class>it.manuelgozzi.aster.jpa.entity.AccountEntity</class>
<class>it.manuelgozzi.aster.jpa.entity.MovementEntity</class>
<class>it.manuelgozzi.aster.jpa.entity.MovementGroupEntity</class>
<class>it.manuelgozzi.aster.jpa.entity.PersonalGoalEntity</class>
<class>it.manuelgozzi.aster.jpa.entity.PersonalInformationEntity</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<!-- <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:3306/aster"/>
<property name="hibernate.connection.password" value="postgres"/>
<property name="hibernate.connection.username" value="1234"/> -->
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:3306/aster"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="1234"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
</properties>
</persistence-unit>
</persistence>
我想念什么?我测试了与数据库的连接,看来还可以,在测试ping时没有此类错误。我不明白为什么我什么都看不到。
我针对 Hibernate JPA 2.1 设置了连接配置文件。
答案 0 :(得分:0)
我终于做到了。
我忘记在我的pom.xml中插入休眠依赖项。完成后,我配置了一个Hibernate Console,然后重试。
现在一切正常,我错过了最重要的一点...