MySQL one-to-many, Java, hibernate - java

First...sorry for my description...I hope I can be clear.
I want to create a project, where I have cars and drivers. One car can have one driver and one driver can have many cars.
#Entity
#Table(name = "car")
public class Car {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "carid")
private int id;
#Column(name = "car_producator")
private String producator;
#Column(name = "car_model")
private String model;
#Column(name = "car_culoare")
private String culoare;
#Column(name = "car_esteInchiriata")
private boolean esteInchiriata;
#ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
#JoinColumn(name="driver_id")
private Driver driver;
private int car_soferID;
[...]
}
#Entity
#Table(name = "driver")
public class Driver {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "driver_id")
private int driver_id;
#Column(name = "driver_name")
private String name;
#Column(name = "driver_license")
private String license;
#Column(name = "driver_phonenr")
private String phoneNr;
#OneToMany(mappedBy = "driver", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
private List<Car> masini;
[...]
}
and this is the mysql syntax, which i don't understand very clear, if i have one to many relationships, do I need a 3rd table where i have id, carID and driverID for that car? sorry for my dummy questions
CREATE DATABASE IF NOT EXISTS `employee_directory`;
USE `employee_directory`;
DROP TABLE IF EXISTS `driver`;
CREATE TABLE `driver` (
`driver_id` int(11) NOT NULL AUTO_INCREMENT,
`driver_name` varchar(45) DEFAULT NULL,
`driver_license` varchar(45) DEFAULT NULL,
`driver_phonenr` varchar(45) DEFAULT NULL,
PRIMARY KEY (`driver_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
INSERT INTO `driver` VALUES
(1,'Tora1ie','Andrews','leslie#mail#com'),
(2,'Tora2','Baumgarten','emma#mail#com'),
(3,'Tora3i','Gupta','avani#mail#com'),
(4,'Tora4','Petrov','yuri#mail#com'),
(5,'Tora5','Vega','juan#mail#com');
create table `car` (
`carid` int unsigned not null auto_increment,
`driver_id` int unsigned not null,
`car_producator` varchar(45) DEFAULT NULL,
`car_mode` varchar(45) DEFAULT NULL,
`car_culoare` varchar(45) DEFAULT NULL,
TINYINT
`car_esteInchiriata` TINYINT(1) DEFAULT NULL,
index car_driver_index(`driver_id`),
foreign key (`driver_id`) references driver(`driver_id`) on delete cascade,
primary key(`carid`)
);

Its completely upto you to decide as both the solution will work.
For the current code it will not create a third table but every row of Car table will have a driver value.
But it would be better if you make #ManyToMany as in future it will be easy for you even if the requirement changes and will have separate table.

Related

Unexpected table created by ddl-auto update

I have spring-boot application with this two JPA entities joined by one-to-many relation.
#Entity
#Table(name = "todos")
public class ToDo {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column
private String description;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "user_id")
private User user;
#Column
private LocalDate targetDate;
public ToDo() {
}
// Constructors, getters, setter, etc.
}
#Entity
#Table(name = "users")
public class User {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(unique = true, nullable = false)
private String username;
#Column(nullable = false)
private String password;
#OneToMany(
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<ToDo> toDos = new ArrayList<>();
// Constructors, getters, setter, etc.
}
For such kind of relation I expect to have only two tables but Hibernate create three.
Hibernate: create table todos (id bigserial not null, description varchar(255), target_date date, user_id int8, primary key (id))
Hibernate: create table users (id bigserial not null, password varchar(255) not null, username varchar(255) not null, primary key (id))
Hibernate: create table users_to_dos (user_id int8 not null, to_dos_id int8 not null)
The last one look useless. Why it created and could I prevent that? May be something is wrong in code?
Since your toDos list on the user entity does not have a #JoinColumn annotation, hibernate assumes there's an additional mapping table for this and creates it.
Add the #JoinColumn annotation to the field and it will not be created
See more on this guide
#OneToMany(mappedBy="speciality",fetch = FetchType.LAZY)
#JsonIgnore
private Set<DepartmentMaster> departmentSpeciality;
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name="SPECALITY_ID")
#JsonIgnore    
private SpecialityMaster speciality;
Try to do the mapping like this I don't think it should create any problem.

#OneToMany #JoinTable usage with three tables

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;
}

OneToMany mapping on Embeddable key

I am attempting to build a permission rule for accessing items (stored in table tab) by the users (stored in table users). The availability whether to see something is stored in permissions_tabs table.
The result should be as if the statement is run (for the user with id=2):
SELECT project.tab.tab_id, project.tab.parent, project.tab.name
FROM project.tab
INNER JOIN project.permissions_tabs
ON project.tab.tab_id=project.permissions_tabs.tab_id
WHERE permissions_tabs.user_id=2 AND permissions_tabs.view=true;
I am attempting to do it via the #OneToMany annotation, but it fails - I receive the message:
Deployment failed. The message was: Exception Description: The
#JoinColumns on the annotated element [field allowedTabs] from the
entity class [class
com.jtsmr.scheduler.persistence.entities.UsersEntity] is incomplete.
When the source entity class uses a composite primary key, a
#JoinColumn must be specified for each join column using the
#JoinColumns. Both the name and the referencedColumnName elements must
be specified in each such #JoinColumn.
Before amending the DB and adding the permissions_tab, it all worked. When I added it - I was unable to write the correct #OneToMany annotation, neither I succeeded in finding manual for my case.
If it is not possible, a solution via JPQL will suffice (I was unable to construct a join operation).
Here is my setup:
DB (creation statements for easier understanding):
CREATE TABLE `users` (
`user_id` bigint(20) NOT NULL,
`username` varchar(45) NOT NULL,
`password` varchar(45) NOT NULL,
`name` varchar(45) NOT NULL,
`email` varchar(80) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_id_UNIQUE` (`user_id`),
UNIQUE KEY `username_UNIQUE` (`username`)
);
CREATE TABLE `tab` (
`tab_id` bigint(20) NOT NULL AUTO_INCREMENT,
`parent` bigint(20) NOT NULL DEFAULT '0',
`name` varchar(45) NOT NULL,
PRIMARY KEY (`tab_id`)
);
CREATE TABLE `permissions_tabs` (
`user_id` bigint(20) NOT NULL,
`tab_id` bigint(20) NOT NULL,
`to_view` bit(1) DEFAULT b'0',
`to_edit` bit(1) DEFAULT b'0',
PRIMARY KEY (`user_id`,`tab_id`),
KEY `user_id_idx` (`user_id`),
KEY `tab_id_idx` (`tab_id`),
CONSTRAINT `tab_id` FOREIGN KEY (`tab_id`) REFERENCES `tab` (`tab_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
);
The JPA Mapping is as follows (functions omitted):
Tabs:
#Entity
#Table(name = "tab")
public class TabEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "tab_id", insertable = false, updatable = false)
private Long tabId;
#Column(name = "parent", insertable = false, updatable = false)
private Long parent;
#Column(name = "name", insertable = false, updatable = false)
private String name;
}
Users:
#Entity
#Table(name = "users")
public class UsersEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "user_id")
private Long userId;
#Column(name = "username")
private String username;
#Column(name = "password")
private String password;
#Column(name = "name")
private String name;
#Column(name = "email")
private String email;
#OneToMany
#JoinTable(
name = "permissions_tabs",
joinColumns
= {
#JoinColumn(name = "user_id", referencedColumnName = "user_id")},
inverseJoinColumns
= {
#JoinColumn(name = "tab_id", referencedColumnName = "tab_id")})
private List<PermissionsTabsEntity> allowedTabs;
}
Primary key for the PermissionsTabsEntity class:
#Embeddable
public class PermissionsTabsPK implements Serializable {
#Column(name = "user_id")
private Long userId;
#Column(name = "tab_id")
private Long tabId;
}
And the PermissionsTabsEntity:
#Entity
#Table(name = "permissions_tabs")
public class PermissionsTabsEntity implements Serializable {
#EmbeddedId
private PermissionsTabsPK id;
#Column(name = "to_view")
private boolean toView;
#Column(name = "to_edit")
private boolean toEdit;
}
Thank you in advance!

Spring Data JPA. Using composite natural key in relationship between entities

I use Spring Data JPA (version is 1.7.2.RELEASE) and MySQL 5.5.
Here is the simplified version of my tables:
CREATE TABLE `station` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
CREATE TABLE `ticket` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`trip_id` bigint(20) unsigned NOT NULL,
`wagon_number` tinyint(4) unsigned NOT NULL,
`place_number` tinyint(4) unsigned NOT NULL,
`departure_station_id` bigint(20) unsigned NOT NULL,
`arrival_station_id` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `departure_trip_station_fk_idx` (`trip_id`,`departure_station_id`),
KEY `arrival_trip_station_fk_idx` (`trip_id`,`arrival_station_id`),
CONSTRAINT `arrival_trip_station_fk` FOREIGN KEY (`trip_id`, `arrival_station_id`) REFERENCES `trip_station` (`trip_id`, `station_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `departure_trip_station_fk` FOREIGN KEY (`trip_id`, `departure_station_id`) REFERENCES `trip_station` (`trip_id`, `station_id`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
CREATE TABLE `train` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`number` int(11) unsigned NOT NULL,
`name` varchar(64) NOT NULL,
`enabled` bit(1) NOT NULL DEFAULT b'1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1$$
CREATE TABLE `train_station` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`train_id` bigint(20) unsigned NOT NULL,
`station_id` bigint(20) unsigned NOT NULL,
`departure_time` mediumint(8) unsigned NOT NULL,
`arrival_time` mediumint(8) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `train_station_uq` (`train_id`,`station_id`),
KEY `train_id_idx` (`train_id`),
KEY `id_idx` (`station_id`),
KEY `station_fk_idx` (`station_id`),
CONSTRAINT `station_fk` FOREIGN KEY (`station_id`) REFERENCES `station` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `train_fk` FOREIGN KEY (`train_id`) REFERENCES `train` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
CREATE TABLE `trip` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`train_id` bigint(20) unsigned NOT NULL,
`departure_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `train_id` (`train_id`),
CONSTRAINT `timetable_fk` FOREIGN KEY (`train_id`) REFERENCES `train` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=246 DEFAULT CHARSET=latin1$$
CREATE TABLE `trip_station` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`train_id` bigint(20) unsigned NOT NULL,
`station_id` bigint(20) unsigned NOT NULL,
`trip_id` bigint(20) unsigned NOT NULL,
`arrival_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`departure_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `trip_station_uq` (`trip_id`,`station_id`),
KEY `trip_fk_idx` (`trip_id`),
KEY `train_station_fk_idx` (`train_id`,`station_id`),
CONSTRAINT `train_station_fk` FOREIGN KEY (`train_id`, `station_id`) REFERENCES `train_station` (`train_id`, `station_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `trip_fk` FOREIGN KEY (`trip_id`) REFERENCES `trip` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
Here are my entities:
#Entity
#Getter
#Setter
public class Station {
#Id
private long id;
#Basic
private String name;
#OneToMany(mappedBy = "station", fetch = FetchType.LAZY)
private Collection<TrainStation> stationTrains;
}
#Entity
#Getter
#Setter
public class Ticket {
#Id
private long id;
#Basic
#Column(name = "place_number")
private byte placeNumber;
#Basic
#Column(name = "wagon_number")
private byte wagonNumber;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumns({
#JoinColumn(name = "trip_id", referencedColumnName = "trip_id", nullable = false),
#JoinColumn(name = "departure_station_id", referencedColumnName = "station_id", nullable = false)
})
private TripStation departureTripStation;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumns({
#JoinColumn(name = "trip_id", referencedColumnName = "trip_id", nullable = false),
#JoinColumn(name = "arrival_station_id", referencedColumnName = "station_id", nullable = false)
})
private TripStation arrivalTripStation;
}
#Entity
#Getter
#Setter
public class Train {
#Id
private long id;
#Basic
private int number;
#Basic
private String name;
#Basic
#Column(name = "enabled", columnDefinition = "BIT", length = 1)
private boolean enabled;
#OneToMany(mappedBy = "train", fetch = FetchType.LAZY)
private List<TrainStation> trainStations;
#OneToMany(mappedBy = "train", fetch = FetchType.LAZY)
private List<Trip> trips;
}
#Entity
#Table(name = "train_station", schema = "", catalog = "rail_db",
uniqueConstraints = #UniqueConstraint(columnNames = { "train_id", "station_id" })
)
#Getter
#Setter
public class TrainStation {
#Id
private long id;
#Basic
#Column(name = "departure_time")
private int departureTime;
#Basic
#Column(name = "arrival_time")
private int arrivalTime;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "train_id", referencedColumnName = "id", nullable = false)
private Train train;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "station_id", referencedColumnName = "id", nullable = false)
private Station station;
#OneToMany(mappedBy = "trainStation", fetch = FetchType.LAZY)
private Collection<TripStation> tripStations;
}
#Entity
#Getter
#Setter
public class Trip {
#Id
private long id;
#Basic
#Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
#Column(name = "departure_date")
private DateTime departureDate;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "train_id", referencedColumnName = "id", nullable = false)
private Train train;
#OneToMany(mappedBy = "trip", fetch = FetchType.LAZY)
private Collection<TripStation> tripStations;
}
#Entity
#Table(name = "trip_station", schema = "", catalog = "rail_db",
uniqueConstraints = #UniqueConstraint(columnNames = { "trip_id", "station_id" })
)
#Getter
#Setter
public class TripStation {
#Id
private long id;
#Basic
#Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
#Column(name = "arrival_date")
private DateTime arrivalDate;
#Basic
#Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
#Column(name = "departure_date")
private DateTime departureDate;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "trip_id", referencedColumnName = "id", nullable = false)
private Trip trip;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumns({
#JoinColumn(name = "train_id", referencedColumnName = "train_id", nullable = false),
#JoinColumn(name = "station_id", referencedColumnName = "station_id", nullable = false)
})
private TrainStation trainStation;
#OneToMany(mappedBy = "departureTripStation", fetch = FetchType.LAZY)
private Collection<Ticket> departureTickets;
#OneToMany(mappedBy = "arrivalTripStation", fetch = FetchType.LAZY)
private Collection<Ticket> arrivalTickets;
}
As you can see, my tables contain the surrogate primary keys and the composite natural keys (e.g. trip_station has UNIQUE KEY trip_station_uq (trip_id,station_id)).
For relationships between entities I offen use composite natural keys because they reflect the logic of domain.
But then I get this runtime exception:
ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/rail/config/JpaConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
...
Caused by: org.hibernate.AnnotationException: referencedColumnNames(trip_id, station_id) of com.xxx.rail.domain.entity.Ticket.arrivalTripStation referencing com.xxx.rail.domain.entity.TripStation not mapped to a single property
...
I want to understand what is wrong?
Is it possible to use natural composite keys (which are not primary keys) for relationships when surrogate primary keys exist?

Mapping java objects using hibernate annotations?

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!

Categories

Resources