I am creating entity relationships in Spring Boot data JPA. Since those tables being legacy I am not able to modify or add columns. Issue is I am getting error if point part of embedded Id.
My entity classes looks like below:
Class Customer {
#EmbededId
private CustomerPk id;
#Column("NAME")
private String name;
#OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="customerDetails")
private List<Purchase> purchaseDetails;
...
}
#Embeddable
Class CustomerPk {
#Column("CUSTOMER_ID")
private String customerId
#Column("PURCHASE_ID")
private String productId;
#Column("PURCHASE_DATE")
private String date;
}
Purchase Entity looks like below:
Class Purchase {
#EmbededId
private PurchasePK id;
#Column("TRANSACTION_NAME")
private String transactionName;
#ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
#JoinColumns({
#JoinColumn(name="CUSTOMER_ID" referencedColumnName="CUSTOMER_ID")
#JoinColumn(name="PURCHASE_ID" referencedColumnName="PURCHASE_ID")
)}
private Customer customerDetails;
...
}
#Embeddable
Class PurchasePK {
#Column("CUSTOMER_ID")
private String customerId
#Column("PURCHASE_ID")
private String productId;
#Column("TRANSACTION_DATE")
private String date;
}
With above structure I am getting org.hibernate.AnnotationException: referencedColumnNames(CUSTOMER_ID, PURCHASE_ID) of Purchase.customerDetails referencing Customer not mapped to a single property.
If I remove date property from CustomerPK, I am able to make the server up. But with current requirement I need date to be part of the CustomerPK class.
I think if I use part of the composite key as Join Columns I am getting this error.
Working version:
#Entity
public class Customer {
#EmbeddedId
private CustomerPk id;
#Column(name = "NAME")
private String name;
#OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "customerDetails")
private List<Purchase> purchaseDetails;
}
#Embeddable
public class CustomerPk implements Serializable {
#Column(name = "CUSTOMER_ID")
private String customerId;
#Column(name = "PURCHASE_ID")
private String productId;
#Column(name = "PURCHASE_DATE")
private String date;
}
#Entity
public class Purchase {
#EmbeddedId
private PurchasePK id;
#Column(name = "TRANSACTION_NAME")
private String transactionName;
#ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinColumns({
#JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID", insertable = false, updatable = false),
#JoinColumn(name = "PURCHASE_ID", referencedColumnName = "PURCHASE_ID", insertable = false, updatable = false),
#JoinColumn(name = "PURCHASE_DATE", referencedColumnName = "PURCHASE_DATE", insertable = false, updatable = false)
})
private Customer customerDetails;
}
#Embeddable
public class PurchasePK implements Serializable {
#Column(name = "CUSTOMER_ID")
private String customerId;
#Column(name = "PURCHASE_ID")
private String productId;
#Column(name = "TRANSACTION_DATE")
private String date;
}
Conclusion:
The provided information from #Ray was valid, you missed adding the required join columns to represent the full entity relation, regarding your note for the same #Ray point, yes you are right both columns usage is different but also both columns have their own name which it will not override any row value on runtime.
The result of the above tables and representation is as follows:
create table customer
(
customer_id varchar(255) not null,
purchase_date varchar(255) not null,
purchase_id varchar(255) not null,
name varchar(255),
primary key (customer_id, purchase_date, purchase_id)
);
create table purchase
(
customer_id varchar(255) not null,
transaction_date varchar(255) not null,
purchase_id varchar(255) not null,
transaction_name varchar(255),
purchase_date varchar(255),
primary key (customer_id, transaction_date, purchase_id)
);
alter table purchase
add constraint FK6rkrb8rq8x56kai7g5gm32d1y foreign key (customer_id, purchase_date, purchase_id) references customer;
Related
I am trying to do one to many association by a non primary key of the parent. I am using JPA 2.1 with hibernate. I have found several similar questions. But i think my case is a bit different.
I have two table :
ProfileBasic and Phonenumber.
#Entity
public class ProfileBasic {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "profile_id")
private Long id;
//....some columns.
#OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
#JoinColumn(name = "profile_id")
private List<PhoneNumber> phone_number;
// getters-setters
}
public class PhoneNumber implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
// getters-setters and other columns
}
Database tables :
CREATE TABLE `profilebasic` (
`profile_id` bigint(20) NOT NULL,
`available` varchar(255) DEFAULT NULL,
`birth_date` varchar(255) DEFAULT NULL,
`blood_Group` varchar(255) DEFAULT NULL,
`care_of` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`gender` varchar(255) DEFAULT NULL,
`marital_status` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`profession` varchar(255) DEFAULT NULL,
`religion` varchar(255) DEFAULT NULL,
`user_id` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for table `profilebasic`
--
ALTER TABLE `profilebasic`
ADD PRIMARY KEY (`profile_id`);
CREATE TABLE `phonenumber` (
`id` bigint(20) NOT NULL,
`number` varchar(255) DEFAULT NULL,
`profile_id` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for table `phonenumber`
--
ALTER TABLE `phonenumber`
ADD PRIMARY KEY (`id`),
ADD KEY `FK8sfxu3ejjpklkd3njt3767ape` (`profile_id`);
--
-- Constraints for table `phonenumber`
--
ALTER TABLE `phonenumber`
ADD CONSTRAINT `FK8sfxu3ejjpklkd3njt3767ape` FOREIGN KEY (`profile_id`) REFERENCES `profilebasic` (`profile_id`);
I have other tables and have made several views from those tables, where some cases profile_id is the Primary Key on those view. I have done successfully one to many association from views, where primary key is profile_id. But i have a view, where profile_id is not PK, as a result in time of fetching, it is generating right query but with wrong value.
Hibernate: select phone_numb0_.profile_id as profile_3_18_0_, phone_numb0_.id as id1_18_0_, phone_numb0_.id as id1_18_1_, phone_numb0_.number as number2_18_1_ from PhoneNumber phone_numb0_ where phone_numb0_.profile_id=?
2020-08-23 04:00:48.396 TRACE 9292 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [21451]
Here parameter [1] as [BIGINT] - [21451] is the wrong value : PK of the view, where right value will be 1134. But as i told earlier, this is working where the primary key of the view is profile_id.
I have seen several questions in stackoverflow. Now i want to know : is there any way by which i can associate the phone number by one-to-many, where profile_id is not PK. If it is not possible, i have to read the phone number for each row of the views.
View Entity :
#Entity
#Table(name = "donner_assing_show")
public class DonnerAssingShow implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#Column(name = "donner_assingment_id")
private long donnerAssingmentId;
#Size(max = 255)
#Column(name = "agent_id")
private String agentId;
#Size(max = 255)
#Column(name = "donner_id")
private String donnerId;
#Size(max = 255)
#Column(name = "assing_date")
private String assingDate;
#Lob
#Size(max = 2147483647)
#Column(name = "assing_note")
private String assingNote;
#Size(max = 255)
#Column(name = "need_date")
private String needDate;
#Size(max = 255)
#Column(name = "post_id")
private String postId;
#Size(max = 255)
#Column(name = "blood_manage_status")
private String bloodManageStatus;
#Basic(optional = false)
#NotNull
#Column(name = "profile_id")
private long profileId;
#Size(max = 255)
#Column(name = "available")
private String available;
#Size(max = 255)
#Column(name = "birth_date")
private String birthDate;
#Size(max = 255)
#Column(name = "blood_Group")
private String bloodGroup;
#Size(max = 255)
#Column(name = "care_of")
private String careOf;
// #Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
#Size(max = 255)
#Column(name = "email")
private String email;
#Size(max = 255)
#Column(name = "gender")
private String gender;
#Size(max = 255)
#Column(name = "marital_status")
private String maritalStatus;
#Size(max = 255)
#Column(name = "name")
private String name;
#Size(max = 255)
#Column(name = "profession")
private String profession;
#Size(max = 255)
#Column(name = "religion")
private String religion;
#Size(max = 255)
#Column(name = "user_id")
private String userId;
#OneToMany
// #OneToMany(fetch = FetchType.EAGER)
#LazyCollection(LazyCollectionOption.FALSE)
#JoinColumn(name = "profile_id")
private List<PhoneNumber> phone_number;
// #OneToMany
#OneToMany(fetch = FetchType.EAGER)
// #LazyCollection(LazyCollectionOption.FALSE)
#JoinColumn(name = "profile_id")
private List<Address> addressList;
// constructor-getter/setters
}
GitHub Link of the project where stacked
Unit Test of the code
Dump Data of the project
The join column is not required to be part of the primary key, or using the same column name in both tables. You can specify which column you want to join by using "referenceColumnName".
#Entity
public class ProfileBasic
{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "profile_id")
private Long id;
//....some columns.
#OneToMany(cascade = CascadeType.ALL, mappedBy = "profile", orphanRemoval = true)
private List<PhoneNumber> phone_number;
// getters-setters
}
public class PhoneNumber implements Serializable
{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
#Column(name = "profile_id")
#JoinColumn(name = "profile_id", referencedColumnName = "profile_id", nullable = false)
private ProfileBasic profile;
// getters-setters
}
You should correct your mapping in this way:
#Entity
public class ProfileBasic {
//....some columns.
#OneToMany(cascade = CascadeType.ALL, mappedBy = "profile", orphanRemoval = true)
private List<PhoneNumber> phoneNumbers;
}
#Entity
public class PhoneNumber implements Serializable {
// getters-setters and other columns
#ManyToOne
#JoinColumn(name = "profile_id", nullable = false)
private ProfileBasic profile;
}
Comments:
The #JoinColumn annotation should be used on side that owns foreign key column (this is PhoneNumber in your case).
It is not necessary to use the referencedColumnName when the FK refereed to the PK column.
It is good to follow java naming conventions. So, it is better to use phoneNumbers as a property name instead of phone_number.
I have 2 tables in MySql and I have mapped them using hibernate in Spring: users and roles .
I have created one more table: user_roles but I don't know how to map it in hibernate.
You can see the table structure below:
CREATE TABLE users (
username varchar(30) NOT NULL,
email varchar(50) NOT NULL,
password varchar(255) NOT NULL,
first_name varchar(40) NOT NULL,
last_name varchar(40) NOT NULL,
date_of_birth Date,
phone_number varchar(20),
PRIMARY KEY (username)
);
CREATE TABLE roles (
role_id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
PRIMARY KEY (role_id)
);
CREATE TABLE user_roles (
username VARCHAR(30) NOT NULL,
role_id INTEGER NOT NULL,
PRIMARY KEY (username, role_id)
);
Here is the mapping for the roles tables:
#Entity
#Table(name = "roles")
public class Role implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="role_id")
private Integer id;
private String name;
}
Here is the mapping for the users table:
#Entity
#Table(name = "users")
#JsonInclude(JsonInclude.Include.NON_NULL)
public class User implements Serializable {
#Id
#NotEmpty
#Size(min = 5, max = 15)
#Column(name = "username")
private String username;
#Email
#NotEmpty
#Column(name = "email")
private String email;
#NotEmpty
#Size(min = 5)
#Column(name = "password")
private String password;
#NotEmpty
#Size(max = 40)
#Column(name = "first_name")
private String firstName;
#NotEmpty
#Size(max = 40)
#Column(name = "last_name")
private String lastName;
...
}
I have created the POJO for the user_role table, but I don't know how to use hibernate on it, I am using #EmbeddedId annotation but it is not working. I don't know how to show the 2 classes above that they are embeddable
#Entity
#Table(name = "user_roles")
#JsonInclude(JsonInclude.Include.NON_NULL)
public class UserRole implements Serializable {
public UserRole() { }
public UserRole(User username, Role role_id) {
this.username = username;
this.role_id = role_id;
}
private static final long serialVersionUID = -2947211066236048069L;
#EmbeddedId
private User username;
#EmbeddedId
private Role role_id;
}
How can I map the "UserRole" class to 'user_role' in hibernate? Thank you!
There are two different ways which you can map user_roles table, which I suggest the first one :
1.
#Entity
#Table(name = "users")
public class User
{
#ManyToMany(targetEntity = Role.class)
#JoinTable(name = "users_roles", joinColumns = #JoinColumn(name = "user_id"), inverseJoinColumns = #JoinColumn(name = "role_id"))
#NotAudited
private Set<Role> roles = new HashSet<>();
}
2.
#Embeddable
public class UserRoleId implements java.io.Serializable
{
#Column(name = "user_id", nullable = false)
private long userId;
#Column(name = "role_id", nullable = false)
private long roleId;
public UserRoleId()
{
}
public UserRoleId(long userId, long roleId)
{
this.userId = userId;
this.roleId = roleId;
}
//hashcode equal
}
Then create the entity.
#Entity
#Table(name = "users_roles")
public class Userroles implements java.io.Serializable
{
#EmbeddedId
private UserRoleId id;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "user_id", nullable = false, insertable = false, updatable = false)
#NotNull
private Users users;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "role_id", nullable = false, insertable = false, updatable = false)
#NotNull
private Role role;
}
I have been stuck with one scenario in hibernate, i tried looking for such scenario discussion but i couldnt get so raing here for any suggestions or help,
i have three tables category , category_artical, artical.
CREATE TABLE `category` (
`category_id` int(11) NOT NULL AUTO_INCREMENT,
`category_name` varchar(45) NOT NULL,
`category_description` varchar(45) NOT NULL,
PRIMARY KEY (`category_id`)
);
CREATE TABLE `article` (
`article_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(70) NOT NULL,
`description` varchar(250) NOT NULL,
`keywords` varchar(150) NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`article_id`)
);
CREATE TABLE `category_article` (
`category_id` int(11) NOT NULL,
`article_id` int(11) NOT NULL,
'category_article_status' varchar(1) NOT NULL.
'category_article_type' varchar(2) NOT NULL,
PRIMARY KEY (`category_id`,`article_id`),
UNIQUE KEY `article_id_UNIQUE` (`article_id`),
KEY `fk_category` (`category_id`),
KEY `fk_article` (`article_id`),
CONSTRAINT `fk_article` FOREIGN KEY (`article_id`) REFERENCES `article` (`article_id`),
CONSTRAINT `fk_category` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`)
);
i have entity for category,
#Entity
#Table(name = "CATEGORY")
public class Category {
private long id;
private String name;
#Id
#GeneratedValue
#Column(name = "CATEGORY_ID")
public long getId() {
return id;
}
#OneToMany(cascade = CascadeType.ALL)
#JoinTable(
name = "CATEGORY_ARTICLE",`enter code here`
joinColumns = #JoinColumn(name = "CATEGORY_ID"),
inverseJoinColumns = #JoinColumn(name = "ARTICLE_ID")
)
private Set<Article> articles;
// other getters and setters...
/*For Article entity is */
#Entity
#Table(name = "ARTICLE")
public class Article {
private long id;
private String title;
private String description;
private String keywords;
private String content;
#Id
#GeneratedValue
#Column(name = "ARTICLE_ID")
public long getId() {
return id;
}
// other getters and setters...
For category_article i have no entity as i am using #jointable in category
So everything work fine till i have only two column in category_article which are category_id and article_id. But as soon as i added two more columns i am confused how to inser data in those coulmns(category_article_status and category_article_type) which are not null.
any suggestions on this.
You should create another entity for CATEGORY_ARTICLE like this.
#Entity
#Table(name = "CATEGORY_ARTICLE")
public class CategoryArticle{
#Id
private Long id;
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "category_id")
private Category category;
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "article_id")
private Article article;
// other columns
private Boolean categoryArticleStatus;
private Long categoryArticleType;
}
and also should change Category and Article. Remove JoinTable from category entity and change it as bellow.
Category
#Entity
#Table(name = "CATEGORY")
public class Category {
//.....
#OneToMany(mappedBy = "category")
private Set<CategoryArticle> categoryArticleSet;
}
Article
#Entity
#Table(name = "ARTICLE")
public class Article {
//.....
#OneToMany(mappedBy = "article")
private Set<CategoryArticle> categoryArticleSet;
}
I have the following database tables:
CREATE TABLE [user]
(
[id] BIGINT ,
[username] VARCHAR(100) ,
[first_name] VARCHAR(50) ,
[last_name] VARCHAR(50),
PRIMARY KEY (id),
);
CREATE TABLE [message]
(
[id]BIGINT ,
[Subject] VARCHAR(255),
[Body] TEXT ,
[author_id] BIGINT,
PRIMARY KEY (id),
FOREIGN KEY fk_message_user_author_id(author_id) REFERENCES user(id)
);
CREATE TABLE [message_folder]
(
[id] BIGINT ,
[name] VARCHAR(100) (E.g. inbox, sent, drafts etc)
[system_default] BIT
PRIMARY KEY (id),
);
CREATE TABLE [user_messages]
(
[id] BIGINT ,
[user_id] BIGINT ,
[message_id] BIGINT,
[message_folder_id] BIGINT,
[is_read] BIT,
UNIQUE KEY uk_user_message_user_id_message_id(user_id, message_id),
FOREIGN KEY fk_user_messages_user_id(user_id) REFERENCES user(id),
FOREIGN KEY fk_user_messages_message_id(message_id) REFERENCES message(id),
FOREIGN KEY fk_user_messages_message_folder_id(message_folder_id) REFERENCES message_folder(id)
);
I want to be able to map this relationship in my Spring web app where I am using JPA 2.1 with Hibernate provider.
I have the following classes:
User:
#Entity
#Table(name = "user")
public class User extends AuditedEntity {
public interface RegisterUser extends Default {}
#Transient
private static final long serialVersionUID = 1L;
#Column(name = "first_name")
#NotEmpty
private String firstName;
#Column(name = "last_name")
#NotEmpty
private String lastName;
#Column(name = "username")
#NotEmpty
#Pattern(regexp = "^[a-zA-Z0-9]*$")
#UniqueUsername(groups = RegisterUser.class)
private String username;
private MessageBox messageBox;
Message:
#Entity
#Table(name = "message")
public class Message extends AuditedEntity {
#Transient
private static final long serialVersionUID = 1L;
#Column(name = "subject")
#NotEmpty
#Pattern(regexp = "^[a-zA-Z0-9]*$")
private String subject;
#Column(name = "body")
#NotEmpty
#Pattern(regexp = "^[a-zA-Z0-9]*$")
private String body;
#Column(name = "author_id")
private User author;
Message Folder:
#Entity
#Table(name = "message_folder")
public class MessageFolder extends AuditedEntity {
#Transient
private static final long serialVersionUID = 1L;
#Column(name = "last_name")
#NotEmpty
private String name;
#Column(name = "system_default")
#NotEmpty
private boolean systemDefault;
#ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
#JoinTable(name = "user_messages", joinColumns = {#JoinColumn(name = "message_folder_id", updatable = false)},
inverseJoinColumns = {#JoinColumn(name = "message_id", updatable = false)})
private Set<Message> messages = new HashSet<>();
The problem I have is that I want to be able to map message folders back to users using a container class called MessageBox.java as below:
public class MessageBox {
private Set<MessageFolder> messageFolders = new HashSet<>();
public Set<MessageFolder> getMessageFolders() {
return messageFolders;
}
public void setMessageFolders(Set<MessageFolder> messageFolders) {
this.messageFolders = messageFolders;
}
public void addMessageFolder(MessageFolder messageFolder) {
messageFolders.add(messageFolder);
}
public void removeMessageFolder(MessageFolder messageFolder) {
messageFolders.remove(messageFolder);
}
}
Every user will have an instance of MessageBox.java which will contain MessageFolder instances in a set. These in turn will contain messages.
My question is how do I map this relationship using JPA considering I do not have a [message_box] database table. Any suggestions on how to overcome this, even if it involves a schema redesign would be welcome.
Thank you
I am attempting to map two Java classes using Hibernate. When I compile I get the following error:
Caused by: org.h2.jdbc.JdbcSQLException: Column "COMMENTS0_.DELETED" not found;
Have compared to many examples and everything seems to be correct but there is obviously an error in my mapping. Here is my code:
SQL
-- Table 'TEST_STEP_COMMENT'
CREATE TABLE IF NOT EXISTS `TEST_STEP_COMMENT` (
`id` BIGINT NULL DEFAULT NULL AUTO_INCREMENT,
`test_step_comment` TEXT NOT NULL,
`date` DATETIME NOT NULL,
`test_step_id` BIGINT NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_TEST_STEP_COMMENT_TEST_STEPS`
FOREIGN KEY (`test_step_id`)
REFERENCES `TEST_STEPS` (`id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT);
CREATE INDEX `FK_TEST_STEP_COMMENT_TEST_STEPS_idx` ON `TEST_STEP_COMMENT` (`test_step_id` ASC);
CREATE TABLE IF NOT EXISTS `TEST_STEPS` (
`id` BIGINT NULL DEFAULT NULL AUTO_INCREMENT,
`deleted` BOOLEAN NULL DEFAULT FALSE,
`execute` LONGTEXT NOT NULL,
`sequence_order` INT NOT NULL,
`test_case_id` BIGINT NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_TEST_STEPS_TEST_CASES`
FOREIGN KEY (`test_case_id`)
REFERENCES `TEST_CASES` (`id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT);
CREATE INDEX `FK_TEST_STEPS_TEST_CASES_idx` ON `TEST_STEPS` (`test_case_id` ASC);
JAVA
#Entity
#Audited
#Table(name = "TEST_STEPS")
public class TestStep
extends AuditedEntity
implements Identifiable<Long>, Ordered<Integer>, Comparable<TestStep> {
#Id
#GeneratedValue
private Long id;
#ManyToOne(optional = false)
#JoinColumn(name = "test_case_id")
private TestCase testCase;
#Column(name = "execute", nullable = false)
private String execute;
#OneToMany(mappedBy = "testStep", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
#Filter(name = "deletedEntityFilter")
private Set<VerifyStep> verifications = Sets.newLinkedHashSet();
#Column(name = "sequence_order", nullable = false)
private Integer sequenceOrder = 0;
#OneToMany(mappedBy = "testStep", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private Set<TestStepComment> comments = Sets.newLinkedHashSet();
#Column(name = "result")
private Integer result;
#Column(name = "data")
private String data;
//getters/setters etc
}
#Entity
#Audited
#Table(name = "TEST_STEP_COMMENT")
public class TestStepComment
extends AuditedEntity
implements Identifiable<Long>{
#Id
#GeneratedValue
private Long id;
#ManyToOne(optional = false)
#JoinColumn(name = "test_step_id")
private TestStep testStep;
#Column(name = "test_step_comment")
private String comment;
#Column(name = "date")
private Date date;
#Override
public Long getId() {
return id;
//getters/setters etc
}
If anyone has any suggestions of what may be causing my problem it would be much appreciated because my mapping seems to be correct based on multiple examples that I have looked at. Thanks!