I have classes:
#Entity
#Table(schema = "master", name = "master_mapping")
public class MasterMapping extends AuditedEntity {
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "master_field_id")
private MasterFields masterField;
#JsonIgnore
public MasterFields getMasterField() {
return masterField;
}
public void setMasterField(MasterFields masterField) {
this.masterField = masterField;
}
}
and
#Entity
#Table(schema = "master", name = "master_fields")
public class MasterFields extends AuditedEntity {
private String label;
#OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "masterField")
private List<MasterMapping> mappedFields;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<MasterMapping> getMappedFields() {
return mappedFields;
}
public void setMappedFields(List<MasterMapping> mappedFields) {
this.mappedFields = mappedFields;
}
}
and common class with id
#MappedSuperclass
public class AuditedEntity {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
I'm trying to save MasterFields object with MasterMapping, but I'm getting error:
Hibernate: insert into master.master_fields (label) values (?)
Hibernate: select currval('master.master_fields_id_seq')
Hibernate: insert into master.master_mapping (master_field_id) values (?)
SQL Error: 0, SQLState: 23502
ERROR: null value in column "master_field_id" violates not-null constraint
Details: Failing row contains (null).
javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
I'm trying to save it to db with EntityManager.merge(). I see that hibernate can't get generated id from MasterFields object. How can fix it?
Related
I am trying to map a legacy database with JPA so cannot change database structure. I have an entity TableA with a oneToMany collection tableBs where the foreign key is on TableB. The objects in this collection have a ManyToOne relationship with TableC. TableB also has a oneToOne relationship with TableD with the foreign key also on tableB. TableD has a ManyToOne relationship with TableE (tableD having foreign key) and finally TableE has a oneToOne with tableC (tableE having foreign key).
When I call save on tableA I want it to cascade any changes to the collection tableBs so I am cascading save operation. This seems to work fine but when I am adding a new TableB entity to the collection, I set a tableC object on tableB entity but after save this becomes proxy but I need this to be initialised. I have mocked up an example below..
Database tables...
CREATE TABLE TABLEA (tableAPk VARCHAR2(10) PRIMARY KEY);
CREATE TABLE TABLEC (ID NUMBER PRIMARY KEY);
CREATE TABLE TABLEE (ID NUMBER PRIMARY KEY, tableEProperty NUMBER,
CONSTRAINT FK_TABLEC2 FOREIGN KEY (tableEProperty) REFERENCES TABLEC(ID));
CREATE TABLE TABLED (ID NUMBER PRIMARY KEY, tableDProperty NUMBER,
CONSTRAINT FK_TABLEE FOREIGN KEY (tableDProperty) REFERENCES TABLEE(ID));
CREATE TABLE TABLEB (ID NUMBER PRIMARY KEY, tableBProperty VARCHAR2(10), tableBProperty2 NUMBER, tableBProperty3 NUMBER,
CONSTRAINT FK_TABLEA FOREIGN KEY (tableBProperty) REFERENCES TABLEA (tableAPk),
CONSTRAINT FK_TABLEC FOREIGN KEY (tableBProperty2) REFERENCES TABLEC (ID),
CONSTRAINT FK_TABLED FOREIGN KEY (tableBProperty3) REFERENCES TABLED (ID));
CREATE SEQUENCE TABLEA_SEQ START WITH 1;
CREATE SEQUENCE TABLEB_SEQ START WITH 1;
CREATE SEQUENCE TABLEC_SEQ START WITH 1;
CREATE SEQUENCE TABLED_SEQ START WITH 1;
CREATE SEQUENCE TABLEE_SEQ START WITH 1;
Java code:
#Entity
public class TableA {
#Id
private String tableAPk;
#OneToMany(mappedBy="tableBProperty", fetch=FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
private List<TableB> tableBs = new ArrayList<TableB>();
public String getTableAPk() {
return tableAPk;
}
public void setTableAPk(String tableAPk) {
this.tableAPk = tableAPk;
}
public List<TableB> getTableBs() {
return tableBs;
}
public void setTableBs(List<TableB> tableBs) {
this.tableBs = tableBs;
}
}
#Entity
public class TableB {
#Id
#GeneratedValue(strategy=GenerationType.SEQUENCE, generator="TABLEB_SEQ")
#SequenceGenerator(sequenceName = "TABLEB_SEQ", allocationSize = 1, name = "TABLEB_SEQ")
private Integer id;
private String tableBProperty;
#ManyToOne
#JoinColumn(name = "tableBProperty2")
private TableC tableC;
#OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
#JoinColumn(name="tableBProperty3")
private TableD tableD;
public TableB() {}
public TableB(String tableBProperty, TableC tableC, TableD tableD) {
this.tableBProperty = tableBProperty;
this.tableC = tableC;
this.tableD = tableD;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTableBProperty() {
return tableBProperty;
}
public void setTableBProperty(String tableBProperty) {
this.tableBProperty = tableBProperty;
}
public TableC getTableC() {
return tableC;
}
public void setTableC(TableC tableC) {
this.tableC = tableC;
}
public TableD getTableD() {
return tableD;
}
public void setTableD(TableD tableD) {
this.tableD = tableD;
}
}
#Entity
public class TableC {
#Id private Integer id;
#OneToOne(mappedBy="tableC")
private TableE tableE;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public TableE getTableE() {
return tableE;
}
public void setTableE(TableE tableE) {
this.tableE = tableE;
}
}
#Entity
public class TableD {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator="TABLED_SEQ")
#SequenceGenerator(sequenceName = "TABLED_SEQ", allocationSize = 1, name = "TABLED_SEQ")
private Integer id;
#ManyToOne(cascade={CascadeType.PERSIST})
#JoinColumn(name="tableDProperty")
private TableE tableE;
public TableD() {}
public TableD(TableE tableE) {
this.tableE = tableE;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
#Entity
public class TableE {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator="TABLEE_SEQ")
#SequenceGenerator(sequenceName = "TABLEE_SEQ", allocationSize = 1, name = "TABLEE_SEQ")
private Integer id;
#OneToOne(fetch=FetchType.LAZY)
#JoinColumn(name = "tableEProperty")
private TableC tableC;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public TableC getTableC() {
return tableC;
}
public void setTableC(TableC tableC) {
this.tableC = tableC;
}
}
public interface TableARepository extends JpaRepository<TableA, String>{
}
public interface TableCRepository extends JpaRepository<TableC, Integer> {
}
#RunWith(SpringRunner.class)
#SpringBootTest
public class TableARepositoryTest {
private static final Integer TEST_ID = -1;
private static final String TEST_ID_STRING = "TEST1";
#Autowired protected DataSource ds;
#Autowired private TableARepository repoA;
#Autowired private TableCRepository repoC;
protected JdbcTemplate jdbcTemplate;
#Before
public void setUp() throws Exception{
jdbcTemplate = new JdbcTemplate(ds);
String insertASql = "insert into TableA (tableAPk) values (?)";
jdbcTemplate.update(insertASql, new Object[]{TEST_ID_STRING});
String insertCSql = "insert into TableC (id) values (?)";
jdbcTemplate.update(insertCSql, new Object[]{TEST_ID});
String insertESql = "insert into TableE (id, tableEProperty) values (?, ?)";
jdbcTemplate.update(insertESql, new Object[]{TEST_ID, TEST_ID});
}
#After
public void tearDown() throws Exception{
String deleteBSql = "delete from TableB where tableBProperty = ?";
jdbcTemplate.update(deleteBSql, new Object[]{TEST_ID_STRING});
String deleteDSql = "delete from TableD where tableDProperty = ?";
jdbcTemplate.update(deleteDSql, new Object[]{TEST_ID});
String deleteESql = "delete from TableE where ID = ?";
jdbcTemplate.update(deleteESql, new Object[]{TEST_ID});
String deleteASql = "delete from TableA where tableAPk = ?";
jdbcTemplate.update(deleteASql, new Object[]{TEST_ID_STRING});
String deleteCSql = "delete from TableC where ID = ?";
jdbcTemplate.update(deleteCSql, new Object[]{TEST_ID});
}
#Test
public void test() {
TableA tableA = repoA.findById(TEST_ID_STRING).get();
TableC tableC = repoC.findById(TEST_ID).get();
tableA.getTableBs().add(new TableB(TEST_ID_STRING, tableC, new TableD(tableC.getTableE())));
TableA updatedTableA = null;
try {
updatedTableA = repoA.save(tableA);
} catch(Exception e) {
fail("test:"+e.getMessage());
}
assertNotNull(updatedTableA);
assertTrue(Hibernate.isInitialized(updatedTableA.getTableBs().get(0).getTableC()));
}
}
This test passes but if you inspect the returned object, it is a proxy with value TableC_$$_jvst.... My app will then fall over when it tries to serialise this object (which I need).
Wrap your entity in question with :
public static <T> T unproxy(T entity){
Hibernate.initialize(entity)
if(entity instanceof HibernateProxy){
entity = (T)((HibernateProxy)entity).getHibernateLazyInitializer().getImplementation();
} else {
entity = (T)entity
}
return entity;
}
It'll return you the unproxied Object.
I have the following tables in my database (Postgres): questions, responses and question_response.
There is a many to many relationships between questions and responses tables and I have created the entity classes for both of these relations. I now have to create an entity mapping for question_respone table which doesn't have any primary key.
I have read about using #IdClass or #EmbeddedId, however, I am not sure how do I map two foreign keys which are primary keys in two different classes using these annotations.
Note:
updating the entities after implementing the changes mentioned in the comments
Thanks!
questions.sql
CREATE TABLE questions(
id BIGSERIAL PRIMARY KEY,
question VARCHAR(255)
);
respones.sql
CREATE TABLE responses(
id BIGSERIAL PRIMARY KEY,
response VARCHAR(255)
);
question_respone.sql #
CREATE TABLE question_response(
question_id bigint REFERENCES questions ON DELETE CASCADE,
response_id bigint REFERENCES responses ON DELETE CASCADE,
PRIMARY KEY ( question_id, response_id)
);
Question.java
#Entity
#Table(name = "questions")
public class Question{
#Id
#GeneratedValue(strategy=GenerationType.SEQUENCE, generator="qid_seq")
#SequenceGenerator(name = "qid_seq", sequenceName="questions_id_seq")
#Column(name = "id")
private Long id;
#Column(name = "questionText")
private String questionText;
#OneToMany(mappedBy = "question", cascade = CascadeType.ALL, orphanRemoval = true)
private List<QuestionResponse> responses;
public Question() {}
public Question(String questionText) {
super();
this.questionText = questionText;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getQuestionText() {
return questionText;
}
public void setQuestionText(String questionText) {
this.questionText = questionText;
}
public List<QuestionResponse> getResponses() {
return responses;
}
}
QuestionResponse.java
#Entity
#Table(name = "question_response")
public class QuestionResponse {
#Id
#ManyToOne
private Question question;
#Id
#ManyToOne
private Response response;
public QuestionResponse() {
super();
}
public QuestionResponse(Question question, Response response) {
super();
this.question= question;
this.response = response;
}
public Question getQuestion() {
return question;
}
public void setQuestion(Question question) {
this.question = question;
}
public Response getResponse() {
return response;
}
public void setResponse(Response response) {
this.response = response;
}
}
Response.java
#Entity
#Table(name = "responses")
public class Response {
#Id
#GeneratedValue(strategy=GenerationType.SEQUENCE, generator="rid_seq")
#SequenceGenerator(name = "rid_seq", sequenceName="questions_id_seq")
#Column(name = "id")
private Long id;
#Column(name = "responseText")
private String responseText;
#OneToMany(mappedBy = "response", cascade = CascadeType.ALL, orphanRemoval = true)
private List<QuestionResponse> question;
public Response() {}
public Response(String responseText) {
super();
this.responseText = responseText;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getResponseText() {
return responseText;
}
public void setResponseText(String responseText) {
this.responseText = responseText;
}
public List<QuestionResponse> getQuestion() {
return question;
}
}
# WildFly console #
13:54:49,581 ERROR [org.springframework.boot.SpringApplication] (ServerService Thread Pool -- 86) 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:
No identifier specified for entity: com.poc.questionnarie.QuestionResponse
You can break up the many-to-many relationship into a one-to-many-to-one construct as described here:
https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#associations-many-to-many-bidirectional-with-link-entity
I'm using Spring Boot,REST and JPA to build my application. In app, there are 2 entities with one to many relationship.
Entity 1 :
#Entity
#Table( name = "report")
#JsonIgnoreProperties(ignoreUnknown = true)
public class CustomReport {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "REPORT_SEQ")
#SequenceGenerator(sequenceName = "REPORT_SEQ", allocationSize = 1, name = "REPORT_SEQ")
private Long id;
private String name;
private Long createdBy;
private Timestamp lastModifiedTimestamp;
#OneToMany(mappedBy = "customReport", cascade = CascadeType.ALL)
private Set<CustomReportActivity> customReportActivitySet;
public Set<CustomReportActivity> getCustomReportActivitySet() {
return customReportActivitySet;
}
public void setCustomReportActivitySet(Set<CustomReportActivity> customReportActivitySet) {
this.customReportActivitySet = customReportActivitySet;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Timestamp getLastModifiedTimestamp() {
return lastModifiedTimestamp;
}
public void setLastModifiedTimestamp(Timestamp lastModifiedTimestamp) {
this.lastModifiedTimestamp = lastModifiedTimestamp;
}
}
Entity 2:
#Entity
#Table( name = "report_activity")
public class CustomReportActivity {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "REPORT_ACTIVITY_SEQ")
#SequenceGenerator(sequenceName = "REPORT_ACTIVITY_SEQ", allocationSize = 1, name = "REPORT_ACTIVITY_SEQ")
private Long id;
String activityName;
#ManyToOne
#JoinColumn( name="report_id" )
#JsonBackReference
private CustomReport customReport;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getActivityName() {
return activityName;
}
public void setActivityName(String activityName) {
this.activityName = activityName;
}
public CustomReport getCustomReport() {
return customReport;
}
public void setCustomReport(CustomReport customReport) {
this.customReport = customReport;
}
}
And my request JSON is as follows :
{
"name": "test report",
"createdBy" : 129,
"customReportActivitySet": [
{"activityName":"a"},
{"activityName":"b"},
{"activityName":"c"},
{"activityName":"d"},
{"activityName":"e"}
]
}
I want to save both entities in one shot. I've implemented the save functionality in following way:
#RequestMapping(value="/save", method = RequestMethod.POST)
public ResponseEntity<?> addReport(#RequestBody CustomReport customReport) {
return new ResponseEntity<>(customReportService.createCustomReport(customReport), HttpStatus.CREATED);
}
CustomReportService method:
public CustomReport createCustomReport(CustomReport customReport) {
return customReportRepository.save(customReport);
}
CustomRepository:
public interface CustomReportRepository extends CrudRepository<CustomReport, Long> {
}
But I'm getting the constraint violation exception with this:
java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot
insert NULL into ("REPORT_ACTIVITY"."REPORT_ID")
Is it possible to save both entities in one save operation?
Please help!
You would have to add a small piece of code which would populate each CustomReportActivity within the CustomReport instance. Only then the persistence provide can successfully perform the cascade save operation:
public CustomReport createCustomReport(CustomReport customReport) {
customReport.getCustomReportActivitySet.forEach((activity) -> {
activity.setCustomReport(customReport);
});
return customReportRepository.save(customReport);
}
The bottom line is that the dependencies have to be set on both sides of the relationship.
Try this sample, in my case it worked as expected, child entities are saved automatically in a single save operation with creating relations to the parent entity:
#Entity
public class Parent {
#Id
private Long id;
#JoinColumn(name = "parentId")
#OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Child> children;
}
#Entity
public class Child {
#Id
private Long id;
private Long parentId;
}
I have Class Customer ,User , Customer has property manager of user class
Class Customer {
/** The manager. */
#ManyToOne(optional = false, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
#JoinColumn(name = "MANAGER")
#JsonSerialize(using = EntitySerializer.class)
#JsonDeserialize(using = UserDeserializer.class)
private User manager;
}
-------------------------------------
Class User {
#Id
#GeneratedValue(strategy = GenerationType.AUTO, generator = User.TABLE_NAME + "_SEQUENCE")
#SequenceGenerator(name = User.TABLE_NAME + "_SEQUENCE", sequenceName = User.TABLE_NAME + "_SEQ")
#Column(name = FIELD_ID, nullable = false)
#SuppressWarnings("PMD.ShortVariable")
private Integer id;
#Override
public Integer getId() {
return id;
}
#Override
public void setId(final Integer newId) {
//System.out.println("setID");
id = newId;
}
}
Now when i am trying to create criteria
final Criteria criteria = getSession().createCriteria(Customer.class);
criteria.add(Restrictions.ilike("manager", "%"+searchTerm+"%"))
It throwing Error :-
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.User.id
Caused by:
java.lang.IllegalArgumentException: Can not set java.lang.Integer field com.User.id to java.lang.String
**Id field is integer **
Could you please change the following:
final Criteria criteria = getSession().createCriteria(Customer.class); criteria.add(Restrictions.ilike("manager", "%"+searchTerm+"%"))
by the following:
final Criteria criteria = getSession().createCriteria(Customer.class); criteria.add(Restrictions.ilike("manager.name", "%"+searchTerm+"%"))
LIKE clause is applicable to text column only.
this code to used
return this.sessionFactory.getCurrentSession()
.createCriteria(UserTraining.class)
.add(Restrictions.eq("userProfile.userId", userId))
.list();
You used this annotation to error remove
#Table(name="user_training")
#Entity
public class UserTraining {
#Id
#GeneratedValue
#Column(name="id")
private int id;
//Generate getter setter of id
/*
#Column(name="user_id")
private int userId;
*/
#JsonIgnore
#ManyToOne(cascade = {CascadeType.ALL})
#JoinColumn(name = "user_id")
private UserProfile userProfile;
public UserProfile getUserProfile() {
return userProfile;
}
public void setUserProfile(UserProfile userProfile) {
this.userProfile = userProfile;
}
#OneToOne
#JoinColumn(name = "training_id")
private Training training;
#Column(name="view_count")
private int viewCount;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Training getTraining() {
return training;
}
public void setTraining(Training training) {
this.training = training;
}
public int getViewCount() {
return viewCount;
}
public void setViewCount(int viewCount) {
this.viewCount = viewCount;
}
}
I have this scenario:
Table Group
idgroup
groupname
...
Table Interval
idInterval
Description
...
Table group_interval
idInterval
idGroup
active
I had to change the relationship on JPA from manyToMany to manyToOne - OneToMany.
Everything works fine but when I need to insert I have some problems.
First, the exception was that query had idinterval occurred twice, so, couldn't set.
Later, after some changes, I got the exception ... index 8 ... out of bounds, and assume this was relate to setting extra parameters than allowed in the table.
I'm using a mappedSupperClass and extending to classes, and that's the reason I think these errors is relate to extra parameter in the query.
Here's my classes, insert method and stacktrace error.
Base entity
#MappedSuperclass
public abstract class BaseEntity {
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
hashCode, equals and toString
Interval
#Entity
#Table(name = "TUnPbxPauseStatusType")
#Inheritance(strategy = InheritanceType.JOINED)
#AttributeOverride(name = "id", column = #Column(name = "IdStatusType", insertable = false, updatable = false))
public class Interval extends BaseEntity implements Serializable
...
private List<IntervalGroup> listIntervalGroup;
...
#Override
#Id
public Long getId()
{
return super.getId();
}
#Override
public void setId(Long id)
{
super.setId(id);
}
...
#OneToMany(mappedBy = "interval")
public List<IntervalGroup> getListIntervalGroup()
{
return listIntervalGroup;
}
public void setListIntervalGroup(List<IntervalGroup> listIntervalGroup)
{
this.listIntervalGroup = listIntervalGroup;
}
Group
#Entity
#Table(name = "TUnPbxGroup")
#Inheritance(strategy = InheritanceType.JOINED)
#AttributeOverride(name = "id", column = #Column(name = "GroupId", insertable = false, updatable = false))
public class MainGroup extends BaseEntity implements Serializable
...
private List<IntervalGroup> listIntervalGroup;
...
#Override
#Id
public Long getId()
{
return super.getId();
}
#Override
public void setId(Long id)
{
super.setId(id);
}
#OneToMany(mappedBy = "mainGroup")
public List<IntervalGroup> getListIntervalGroup()
{
return listIntervalGroup;
}
public void setListIntervalGroup(List<IntervalGroup> listIntervalGroup)
{
this.listIntervalGroup = listIntervalGroup;
}
IntervalGroup
#Entity
#Table(name = "TUnpbxPauseGroup")
#AttributeOverride(name = "id", column = #Column(name = "fkidstatustype", insertable = false, updatable = false))
#IdClass(IntervalGroup.class)
public class IntervalGroup extends BaseEntity implements Serializable
...
private MainGroup mainGroup;
private Interval interval;
private long idGroup;
#Override
#Id
public Long getId()
{
return super.getId();
}
#Override
public void setId(Long id)
{
super.setId(id);
}
#Id
#Column(name = "fkidGroup", nullable = true)
public long getIdGroup()
{
return idGroup;
}
public void setIdGroup(long idGroup)
{
this.idGroup = idGroup;
}
#ManyToOne(targetEntity = MainGroup.class)
#JoinColumn(name = "fkIdGroup")
public MainGroup getMainGroup()
{
return mainGroup;
}
public void setMainGroup(MainGroup mainGroup)
{
this.mainGroup = mainGroup;
}
#ManyToOne(targetEntity = Interval.class)
#JoinColumn(name = "fkIdStatusType")
public Interval getInterval()
{
return interval;
}
public void setInterval(Interval interval)
{
this.interval = interval;
}
I tried override the id method from supperclass and used transient; Don't use #AttributeOverride in the IntervalGroup class (but i got that the name id doesn't exist);
I tried #Embeddable class, and a lot of another things. Nothing worked.
Maybe not using the BaseEntity class I would solve my problem, but I'd like to use this to use some generics methods.
Here's how I am trying to insert:
IntervalController:
for (IntervalGroup intervalGroups : getItem().getListIntervalGroup())
{
intervalService.save(intervalGroups); //Error happens here.
}
save();//This saves the interval, after save intervalGroup
GenericService
public <T extends BaseEntity> T save(T entity)
{
logger.info("Salvar: " + entity);
if (entity.getId() == null)
{
em.persist(entity);
return entity;
} else {
return em.merge(entity);
}
}
Remembering: Its search works perfectly, the problem happens only when I try to insert.
insert query:
(*fkidstatustype*, icActive, icBlockTime, *fkIdStatusType*, fkIdGroup, nuTime, nuTimeAfterUnlock) values (?, ?, ?, ?, ?, ?, ?)
as shown, the fkidstatustype appears twice.
09:35:46,060 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--0.0.0.0-8080-5) SQL Error: 0, SQLState: S1093
09:35:46,061 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--0.0.0.0-8080-5) The index 8 is out of range.
09:35:46,062 WARN [com.arjuna.ats.arjuna] (http--0.0.0.0-8080-5) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffac100058:7f5df46c:548ad301:27, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization#1b90c55 >: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: The index 8 is out of range.