- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个实体 RoomNight
和 BookingCorporateDetails
,其中 BookingCorporateDetails
在两列(booking_id
和room_night_booking_id
)。
BookingCorporateDetails 是可选的,但 RoomNight 是必需的。我正在尝试在 BookingCorporateDetails 表上创建一个外键连接 -
AbstractJpaEntity.java
@MappedSuperclass
@SuppressWarnings("serial")
public abstract class AbstractJpaEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
protected Date createdAt;
@Column(name = "created_by", length = 32, nullable = true)
protected String createdBy;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
protected Date updatedAt;
@Column(name = "updated_by", length = 32, nullable = true)
protected String updatedBy;
@Column(name = "is_published", columnDefinition = "tinyint(1) default 1")
protected boolean isPublished;
@Column(name = "is_deleted", columnDefinition = "tinyint(1) default 0")
protected boolean isDeleted;
// Getters and Setters
}
AbstractBookingEntity.java
@MappedSuperclass
public abstract class AbstractBookingEntity extends AbstractJpaEntity {
private static final long serialVersionUID = 6980195228404112444L;
@Column(name = "booking_id", nullable = false)
protected String bookingId;
@Column(name = "room_night_booking_id", nullable = false)
protected String roomNightBookingId;
public String getBookingId() {
return bookingId;
}
public void setBookingId(String bookingId) {
this.bookingId = bookingId;
}
public String getRoomNightBookingId() {
return roomNightBookingId;
}
public void setRoomNightBookingId(String roomNightBookingId) {
this.roomNightBookingId = roomNightBookingId;
}
}
BookingCorporateDetailsEntity.java
@Entity(name = "booking_corporate_details")
@Table(name = "booking_corporate_details", uniqueConstraints = { @UniqueConstraint(name = "key_bcd_order_sub_order", columnNames = { "booking_id", "room_night_booking_id" }) })
public class BookingCorporateDetailsEntity extends AbstractBookingEntity {
private static final long serialVersionUID = -5577224607005257364L;
@Column(name = "btc_company")
private String billToCompany;
@Column(name = "cr_company_name", nullable = false)
private String companyName;
@Column(name = "cr_manager_name")
private String managerName;
@Column(name = "cr_manager_email")
private String managerEmail;
@Column(name = "cr_manager_phone")
private String managerPhone;
@OneToOne(optional = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumns({
@JoinColumn(name = "booking_id", referencedColumnName = "booking_id", insertable = false, updatable = false),
@JoinColumn(name = "room_night_booking_id", referencedColumnName = "room_night_booking_id", insertable = false, updatable = false)
})
private RoomNightEntity roomNightEntity;
public RoomNightEntity getRoomNightEntity() {
return roomNightEntity;
}
public void setRoomNightEntity(RoomNightEntity roomNightEntity) {
this.roomNightEntity = roomNightEntity;
}
// Getters And Setters
}
RoomNightEntity.java
@Entity(name = "room_night")
@Table(name = "room_night", uniqueConstraints = { @UniqueConstraint(name = "key_rm_order_sub_order", columnNames = { "booking_id", "room_night_booking_id" }) })
public class RoomNightEntity extends AbstractBookingEntity {
private static final long serialVersionUID = 7661960864475909694L;
@Column(name = "ota_booking_id", nullable = false)
private String otaBookingId;
@Column(name = "property_id", nullable = false)
private Long propertyId;
@Column(name = "room_type_id", nullable = false)
private Integer roomTypeId;
@Column(name = "booking_status", nullable = false)
private Integer bookingStatus;
@Column(name = "occupancy", nullable = false)
private Integer occupancy;
@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "payment_mode", nullable = false)
private String paymentMode;
@Column(name = "stay_date")
@Temporal(TemporalType.DATE)
private Date stayDate;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "roomNightEntity", fetch = FetchType.LAZY)
private BookingCorporateDetailsEntity bookingCorporateDetailsEntity;
// Getters and Setters
}
当我执行代码时,出现以下异常 -
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:201)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:111)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:148)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookingEntityManagerFactory' defined in class path resource [hibernateJPAConfig.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:197)
... 17 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:884)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:340)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 30 more
Caused by: org.hibernate.MappingException: broken column mapping for: bookingCorporateDetailsEntity.roomNightEntity of: com.casa.fabbookingbase.entity.RoomNightEntity
at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:165)
at org.hibernate.persister.entity.AbstractPropertyMapping.initIdentifierPropertyPaths(AbstractPropertyMapping.java:253)
at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:219)
at org.hibernate.persister.entity.AbstractEntityPersister.initOrdinaryPropertyPaths(AbstractEntityPersister.java:2218)
at org.hibernate.persister.entity.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:2265)
at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:3814)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:437)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:344)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:881)
... 35 more
PS:我已经在这里看到了多个示例,但即使尝试了这些解决方案也无法解决问题。
最佳答案
我做了一些测试,它与两个连接列一起工作的唯一方法是从 RoomNightEntity
实体中删除 mappedBy
。
你最终得到了一种没有父子关系的双向映射:BookingCorporateDetailsEntity
@OneToOne(optional = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumns({
@JoinColumn(name = "booking_id", referencedColumnName = "booking_id", insertable = false, updatable = false),
@JoinColumn(name = "room_night_booking_id", referencedColumnName = "room_night_booking_id", insertable = false, updatable = false)
})
private RoomNightEntity roomNightEntity;
RoomNightEntity
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "booking_id", referencedColumnName = "booking_id", insertable = false, updatable = false),
@JoinColumn(name = "room_night_booking_id", referencedColumnName = "room_night_booking_id", insertable = false, updatable = false)
})
private BookingCorporateDetailsEntity bookingCorporateDetailsEntity;
关于java - 一对一多列外键的断列映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42152266/
请看一下我的代码。 int main () { Program* allcommand = new Program; allcommand->addCommand("add", new
因此,当我遇到调试断言时,我正在编写代码。现在我很想知道为什么这段代码不起作用: for(Model::MeshMap::iterator it = obj1->GetMeshes().begin()
这是我上一个问题的延续 Group, Sum byType then get diff using Java streams . 按照建议,我应该作为单独的线程发布,而不是更新原始线程。 因此,通过我
我正在实现一些非常适合 map 的代码。但是,我要迭代的列表中有大量对象,所以我的问题是哪种方法是解决此问题的最佳方法: var stuff = $.map(listOfMyObjects, some
我正在尝试创建一个包含不同类的成员函数指针的映射。成员函数都具有相同的签名。为了做到这一点,我所有的类都继承了一个 Object 类,它只有默认构造函数、虚拟析构函数和一个虚拟 ToString()
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: how do you make a heterogeneous boost::map? 有可能在 C++ 中
我有一个 Mysql 查询,请检查以下内容: SELECT `tbl_classSubjects`.`classID` , `tbl_classSubjects`.`sectionID` , `tbl
抱歉,这可能是一个基本问题。 JNA直接映射和接口(interface)映射有什么区别? 我的解释是否正确: 直接映射 : 直接使用库对象(如 Java 中的静态 main) 接口(interface
在 Twitter's Scala school collections section ,它们显示了一个带有偏函数作为值的 Map: // timesTwo() was defined earlie
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
据我了解,从 scala stdlib 声明一个映射并没有将其专门用于原始类型。我要的不是付出装箱/拆箱的代价,而是同时拥有scala map 的接口(interface)。一个明显的选择是使用 tr
如何为这样的 JSON 响应创建对象映射,它只是一个整数数组: [ 565195, 565309, 565261, 565515, 565292, 565281, 566346, 5
是否可以为 DTO 对象创建映射然后查询它们 而不是域?如果不解释为什么? 如果我需要几个 dtos 怎么办? DTos 是只读的 ID 由 NH 自动生成 将来这些 dtos 将设置映射到链接的 d
我有一个返回的函数(常规代码) [words: "one two", row: 23, col: 45] 在 Scala 中,我将上面更改为 Scala Map,但随后我被迫将其声明为 Map[Str
我有一组与 Vanilla 磅蛋糕烘焙相关的数据(200 行),具有 27 个特征,如下所示。标签caketaste是衡量烤蛋糕的好坏程度,由 bad(0) 定义, neutral(1) , good
我有试图映射到新代码的遗留代码。 OLD_PERSON pid sid name age NEW_PERSON pid sid fid age RESOLVE_PERSON pid fid statu
我有一个表,其中一个字段可以指向其他 3 个表之一中的外键,具体取决于鉴别器值是什么(Project、TimeKeep 或 CostCenter。通常这是用子类实现的,我想知道我有什么 注意子类名称与
我有一个类型 [ST s (Int, [Int])] 的绑定(bind)我正在尝试申请runST使用映射到每个元素,如下所示: name :: [ST s (Int, [Int])] --Of Cou
在我正在进行的项目中,我有以下实体:分析师、客户 和承包商。每个都继承自基类 User。 public abstract class User { public virtual int Id
我想知道是否可以在 Vim 中创建一个映射(对于普通模式),允许用户在映射执行之前输入。 我想为我最常用的 grep 命令创建一个快捷方式的映射。我希望命令允许输入我正在搜索的内容,然后在输入时执行。
我是一名优秀的程序员,十分优秀!