- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
他似乎在通信代码中添加了@OneToMany
和@ManyToOne
,但由于某种原因,在启动Spring应用程序时出现错误
.
类(class)客户:
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.List;
@Getter
@Setter
@Entity
public class Customer extends User {
public Customer(){ // Пустой конструктор для Hibernate
}
public Customer(String name, String lastName,
double wallet, List<Order> orderList){ // Пользовательский конструктор создается,
// когда нам нужно создать новый экземпляр,
// но у нас еще нет ID.
super(name, lastName);
this.wallet = wallet;
this.orderList = orderList;
}
// Поля
private @Id @GeneratedValue Long id;
private double wallet;
@OneToMany(mappedBy = "customer", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonManagedReference
private List<Order> orderList;
// Методы
public void depositMoney(){// Внести деньги на счет
}
public void withdrawMoney(){// Вывести деньги со счета
}
public void makeOrder(){// Сделать заказ
}
}
类(class)顺序:
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Entity;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Getter
@Setter
@Entity
public class Order {
public Order(){
}
public Order(short orderNumber, Customer customer, String address,
String phoneNumber, Date dateOrder, Cook cook, List<Dish> dishes) {
this.orderNumber = orderNumber;
this.customer = customer;
this.address = address;
this.phoneNumber= phoneNumber;
this.dateOrder = dateOrder;
this.cook = cook;
this.dishes = dishes;
}
// Поля
private @Id @GeneratedValue Long id;
private short orderNumber;
@ManyToOne(fetch= FetchType.LAZY, cascade= CascadeType.ALL)
@JsonBackReference
private Customer customer;
private String address;
private String phoneNumber;
private Date dateOrder;
@ManyToOne(fetch= FetchType.LAZY, cascade= CascadeType.ALL)
@JsonBackReference
private Cook cook;
@OneToMany(mappedBy = "order", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonManagedReference
private List<Dish> dishes;
private enum orderStatus{}
// Методы
public double calculateCost(){// Посчитать стоимость заказа
return 0;
}
public void setReview(){// Оставить отзыв и оценку
}
public void cancelOrder(){// Отменить заказ
}
}
2020-03-25 10:21:34.649 ERROR 17876 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.tinychiefdelights.model.Dish.order references an unknown entity: com.tinychiefdelights.model.Order
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at com.tinychiefdelights.TinyChiefDelightsApplication.main(TinyChiefDelightsApplication.java:10) ~[main/:na]
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.tinychiefdelights.model.Dish.order references an unknown entity: com.tinychiefdelights.model.Order
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:97) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1823) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1767) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1655) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:286) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1202) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1233) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378) ~[spring-orm-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
最佳答案
在类 Order 中导入 @entity from javax.persistence
而不是 org.hibernate.annotations.Entity
关于java - org.hibernate.AnnotationException : @OneToOne or @ManyToOne,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60844669/
使用 Entity entity = hibernateTemplate.get(Entity.class, id); 当我点击 entity.getChild() 这是一个 OneToOne 关系时
我刚开始玩弄 Doctrine ORM 库,我正在学习表之间的所有关联。 所以我坚持单向和双向关系的差异。 据我所知,单向关系只有一侧有主键,那一侧是拥有一侧,对吧?双向关系在两个表中都有主键,因此您
我只用@OneToOne 注释我的字段,当我检查数据库(使用 liquibase 生成)时发现数据库列有唯一约束。 这是否意味着@OneToOne 本身就意味着唯一性,例如。一栋建筑只能在一个城市,其
当我同步我的数据库时,我收到了 的错误module' 对象没有属性 'OneToOnefield' models.py 的代码如下: from django.db import models from
我们想使用不在主表中但在从表中的外键创建单向@OneToOne映射。通过提供以下Java代码,Hibernate尝试在表product_ID中找到product列,但在productimage中找不到
我有以下问题。我有 3 个实体,我正在使用 OneToOne 单向: 实体 1 @Entity public class Entity1 implements Serializable{ @Id
我有 2 个类:User 和 UserPicture,它们具有 1:1 关系。 public class User { @Id @GeneratedValue(strategy=G
考虑以下数据库结构 我需要像这样实现单向一对一映射(结构已简化): @Entity @Table(name = "entity") public class Customer { @Id
我有一个实体:HtmlElement,与实体有以下@OneToOne关系:Component 查询参数实体: @Id @Column(name = "QUERY_PARAMETER_ID") priv
我有两个例子,第一个是@OneToOne单向映射,第二个是双向映射。在单向映射中,拥有方表必须包含引用对方表id的连接列;那么在双向中,它们都必须包含彼此的外键列。但是使用自动生成策略生成数据库模式后
我尝试使用 @OneOnOne 关系创建两个表(主表和辅助表) 。(我使用的是 Postgres ) 我这样定义初级表: Class Table1{ @GeneratedValue @Id @Colu
我想创建一个 @OneToOne 映射,其中根实体通过外键约束引用子实体。 @Entity public class MainEntity { @Id private long id;
我有以下实体: //The class Entity is a @MappedSuperclass with id, audit fields, equals and so on. @Entity p
我创建实体 Developer 和 TalentFile,我希望一个开发人员有一个文件 (Cv),当我设置实体时,我已经提交了 null /** * Developers * * @ORM\Table
我正在使用 play 框架 (v2.3.1),并且我有 2 个模型对象;用户和位置。他们彼此之间存在一对一的关系。保存按预期进行,但是当我想从数据库中检索用户时,该位置为空。 我的类(class):
关系所有者中的双向一对一映射是否需要 unique=true? @Entity public class Customer { @Id @GeneratedValue(strategy
我是 UML 图的新手,想编写下面的代码,其中有一个 OneToOne 双双向关联,带有 JPA 注释。 上下文:有个人和团队。每个团队由人组成,每个人只能属于一个团队。团队总是有一个人充当主要领导者
我正在尝试使用 JPA/Hibernate 设置下表: User: userid - PK name Validation: userid - PK, FK(user) code 可能有很多用户,每个
OneToOne 垂直扩展表字段是很常见的方法, 主表存商品资料, 分表存每个客户对应商品的备注和个性化的价格等等, 本文使用Blazor一步步实现这个简单的需求. 1. 基于 实战 10分
假设我有一个 Person 实体和一个 Animal 实体;一个人可以有两个最喜欢的动物,一个动物只能有一个 人喜欢他们的人(一个人喜欢一种动物使得其他人不再可能喜欢/看到该动物)。它是一个@OneT
我是一名优秀的程序员,十分优秀!