创建spring boot表时遇到问题。
具有3个实体,预订和财产与用户实体具有多对一关系:
@Entity
public class Booking implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "uuid-binary")
private UUID booking_id;
@Column(name = "startdate", nullable = false)
private Time startdate;
@Column(name = "enddate", nullable = false)
private Time enddate;
@ManyToOne
@JoinColumn(name="property_id", nullable=false)
private Property property;
@ManyToOne
@JoinColumn(name="tenant_id", nullable=false)
private User user;
@Column(name = "date_made", nullable = false)
private Time date_made;
@Entity()
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "uuid-binary")
private UUID user_id;
@Column(name = "name", nullable = false)
private String name;
@Column(name = "birth_date", nullable = false)
private String birth_date;
@Column(name = "gender", nullable = false)
private String gender;
@Column(name = "age", nullable = false)
private int age;
@Column(name = "address", nullable = false)
private String address;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "role", nullable = false)
private int role;
@OneToMany(mappedBy="user")
private Set<Booking> bookingList;
@OneToMany(mappedBy="user")
private Set<Property> propertiesList;
@Entity
public class Property implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "uuid-binary")
private UUID property_id;
@ManyToOne
@JoinColumn(name="user_id", nullable=false)
private User user;
@Column(name = "name", nullable = false)
private String name;
@Column(name = "location", nullable = false)
private String location;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "rentCpcty", nullable = false)
private int rentCpcty;
启动应用程序时,使用spring.jpa.hibernate.ddl-auto=create-drop,在3个实体中,只有预订属性被创建为表,尽管是运行控制台,但会显示以下消息:
Hibernate:创建用于预订的表(booking_id bytea不为空,date_make时间不为空、enddate时间不为零、startdate时间不为null、property_id bytea不空、tenant_id bytea不为空以及主键(booking_id))
Hibernate:创建表属性(property_id bytea不为空,位置varchar(255)不为空、名称varchar不为空(255)、密码varchar未为空、rent_cpcty int4未为空,user_id bytea未为空以及主键(properties_id))
Hibernate:创建表用户(user_id bytea not null,地址varchar(255)不为null,age int4不为null,
在pgAdmin中,仅显示2个表。
要检查这是否只是一个pgAdmin错误,我使用POST或GET在Postman中使用的用户地址,显示以下错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] throw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: can not execute statement;SQL [n/a];嵌套异常是 org.hibernate.exception.SQLGrammarException: can not execute statement] with root cause org.postgresql.util.PSQLException: ERROR: 语法错误在“user”处或附近
我的pom.xml:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.rentBackEnd</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>backEnd</name>
<description>backEnd for final project</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我有一个名为的bean实体,它使用xml映射到考勤数据库中名为“学生”的表。考勤数据库中的“学生”表还不存在。 尽管属性被设置为“更新”,HiberNate并没有在应用程序启动时在考勤数据库上创建“学生”表。它也没有生成任何异常、警告或查询。它根本不做任何事情。 经过一些测试,我意识到在另一个名为“sms”的数据库中已经存在一个student表。如果我映射@实体转换为另一个表名(在任何数据库中都不
数据库显示 show databases; mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | app_blogcurder | | auth_demo | | canzhieps
我一直通过Workbench和phpMyAdmin在Windows/XAMPP中使用MySQL。创建了10个数据库,我仍然在两个程序中看到它们。我能够使用他们所有的很多周,但今天,其中一半都在给出“错误代码1146-表不存在”。 在Workbench中,当我执行“show databases;”和“show TABLES IN xxxdb;”,它们会给出预期的结果。但当我执行“select*FRO
我创建了一个计算zipfile中文件数量的代码。我当前正在将信息输出到控制台上。我不确定如何开始将输出的信息放入Microsoft SQL Server中的数据库表中。我基本上只需要将它输出到Microsoft SQL server中的一个表,而不是输出到控制台。我有下面的代码:
问题内容: 我正在使用,并且正在尝试运行一个简单的应用程序,尤其是运行在page中描述的应用程序。我的hibernate.cfg.xml文件是: 我(使用maven时)是: 我在链接中使用它: 但是,不可能获得应用程序的工作,即在数据库中hibernate创建表并插入值。无论尝试如何,我总是会收到相同的错误: 在线上的“关系部门不存在”: 我也没有完全相同的错误尝试过。为了抢占某些读者,请不要在数
我的数据确实显示在console.log中,但实际上没有显示在表中,我在这里做错了什么?