@Entity
@Table(name="booking")
public class Booking implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int reservationId;
private String stateroomType;
private double totalAmount;
private int totalGuests;
private int shipId;
private int passId;
//Joining Tables
@OneToOne
@JoinColumn(name="passId")
private Passenger passenger;
@ManyToOne
@JoinColumn(name="shipId")
private Cruise cruise;
@Entity
@Table(name = "shipcruise")
public class Cruise implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int cruiseId;
private String cruiseName;
private LocalDate startDate;
private LocalDate endDate;
private Timestamp destination;
@Entity
@Table(name = "passengers")
public class Passenger implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int passengerId;
private String userName;
private String firstname;
private String lastname;
private String address;
private String city;
private String country;
private String postalCode;
private String password;
当我运行我的项目时,我得到以下错误消息:
异常[EclipseLink-48](Eclipse Persistence Services-2.5.2.v20140319-9AD6ABD):org.Eclipse.Persistence.exceptions.Description异常描述:字段[booking.shipid]存在多个可写映射。只有一个可以定义为可写,所有其他的都必须指定为只读。映射:org.Eclipse.Persistence.mappings.oneToonemapping[cruise]描述符:RelationalDescriptor(com.springmvc.jpa.booking.booking-->[databaseTable(booking)])异常[EclipseLink-48](Eclipse Persistence Services-2.5.v20140319-9ad6abd):org.Eclipse.Persistence.Exception异常描述:字段[booking.passid]存在多个可写映射。只有一个可以定义为可写,所有其他的都必须指定为只读。映射:org.eclipse.persistence.mappings.oneTooneMapping[passer]descriptor:RelationalDescriptor(com.springmvc.jpa.booking.booking-->[databaseTable(booking)])
...............................................................................................
数据库表:
CREATE TABLE `booking` (
`reservationId` int NOT NULL,
`stateroomType` varchar(30) NOT NULL,
`totalGuests` int NOT NULL,
`totalAmount` decimal(10,2) NOT NULL,
`passId` int DEFAULT NULL,
`shipId` int DEFAULT NULL,
PRIMARY KEY (`reservationId`),
KEY `passId` (`passId`),
KEY `shipId` (`shipId`),
CONSTRAINT `booking_ibfk_1` FOREIGN KEY (`passId`) REFERENCES
`passengers` (`passengerId`),
CONSTRAINT `booking_ibfk_2` FOREIGN KEY (`shipId`) REFERENCES
`shipcruise` (`cruiseId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `passengers` (
`passengerId` int NOT NULL AUTO_INCREMENT,
`userName` varchar(50) DEFAULT NULL,
`password` varchar(25) DEFAULT NULL,
`firstname` varchar(30) DEFAULT NULL,
`lastname` varchar(30) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`city` varchar(25) DEFAULT NULL,
`postalCode` varchar(10) DEFAULT NULL,
`country` varchar(20) DEFAULT NULL,
PRIMARY KEY (`passengerId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `shipcruise` (
`cruiseId` int NOT NULL AUTO_INCREMENT,
`CruiseName` varchar(50) DEFAULT NULL,
`shipName` varchar(50) DEFAULT NULL,
`startDate` date NOT NULL,
`endDate` date NOT NULL,
`destination` timestamp NOT NULL,
PRIMARY KEY (`cruiseId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
预订实体。
@Entity
@Table(name="booking")
public class Booking implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer reservationId;
private String stateroomType;
private double totalAmount;
private int totalGuests;
//Joining Tables
@ManyToOne
@JoinColumn(name="passId")
private Passenger passenger;
@ManyToOne
@JoinColumn(name="shipId")
private Cruise cruise;
巡航实体。
@Entity
@Table(name = "shipcruise")
public class Cruise implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer cruiseId;
private String cruiseName;
private LocalDate startDate;
private LocalDate endDate;
private Timestamp destination;
乘客实体。
@Entity
@Table(name = "passengers")
public class Passenger implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer passengerId;
private String userName;
private String firstname;
private int shipId;
private int passId;
//Joining Tables
@OneToOne
@JoinColumn(name="passId")
private Passenger passenger;
@ManyToOne
@JoinColumn(name="shipId")
private Cruise cruise;
我无意中发现我可以在对象上保留更改,即使我没有在事务中写入它们。我想知道这是怎么发生的,因为理论上,如果我不在事务中写入更改,我应该无法更改数据库中的年龄值。PS:如果我删除最后2行,它不会像预期的那样对db产生任何影响。
当尝试将具有双向关联的JPA对象转换为JSON时,我不断得到 我所发现的就是这条线索,它的基本结论是建议避免双向关联。有没有人有办法解决这个spring bug? ------编辑2010-07-24 16:26:22------- 代码片段: 业务对象1: 业务对象2: 控制器: JPA-见习DAO的实施: 坚持不懈xml
问题内容: 我一直在使用Spring JDBC取得了巨大的成功,但是我在这个项目中遇到了很多麻烦。我将在此处发布代码链接(这是一个小而愚蠢的项目,用于测试是否可以启动并运行它,以便将来可以使用Hibernate): xml文件:http://codepaste.net/uw19zc 主文件:http : //codepaste.net/iks1cp 我遇到很多错误,例如 而且我还没有创建一个.ou
问题内容: 当尝试将具有双向关联的JPA对象转换为JSON时,我不断 我所发现的只是该线程,基本上以建议避免双向关联为结尾。有谁知道这个春季错误的解决方法? ------编辑2010-07-24 16:26:22 ------- 代码段: 业务对象1: 业务对象2: 控制器: JPA实施学员DAO: persistence.xml 问题答案: 您可以使用它来打破循环。
我有一个父POM项目,它将spring版本声明为3.2,将hiberate实体管理器版本声明为4.1.1(让我们称之为parent,P)。我有另一个项目,它是这个父级的子级,并继承了提到的依赖项管理(让我们将子级称为C1)。我正在构建一个新的项目,我希望该项目对所提到的父级的子级有影响,并且也依赖于子级C1,(让我们把这个新的子级称为C2)。 父P1(父Pom项目,声明spring 3.2和hib
我使用JPA创建一个表在内置的H2数据库的Wildfly 8.0安装使用Hibernate,但它失败了以下错误消息: 19:15:33,694WARN[org.hornetq.core.server](Thread-18(HornetQ-server-HornetQServerImpl::serverUUID=61b6684a-d6bb-11e4-926e-d9ecaa9f5457-1830325