hibernate

Hibernate having issues with sequence object - unable to call next val

血红的双手。 提交于 2021-01-29 06:29:46
问题 I am using hibernate entity - and sequence generator with it. My database is Oracle 12c. In my sequence generator - it fetches value which is already present in table. I tried looking out for issue - found one simmilar thread Hibernate sequence nextVal resolved but not used (Oracle) But still it did not help . The issue am facing is - it works some times and it does not work some times Below is my code snippet - @Entity @Table(name="TABLE_NAME", schema = "SCHEMA") @SequenceGenerator(name=

Hibernate MappingException: Foreign key must have same number of columns as the referenced primary key

大憨熊 提交于 2021-01-29 05:36:04
问题 I have this entity, called FatRabbitCarrot: @Entity public class FatRabbitCarrot { private Long id; private FatRabbit fatRabbit; private Carrot carrot; @Id @Column(name = "id", nullable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @ManyToOne @JoinColumn(name = "fatRabbit_id", foreignKey = @ForeignKey(name = "FK_FatRabbitCarrot_fatRabbit")) public FatRabbit getFatRabbit() { return fatRabbit; }

Generic DAO implementation, Injection failure @ controller level

江枫思渺然 提交于 2021-01-29 04:23:15
问题 import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import javax.persistence.Transient; import org.apache.log4j.Logger; import org.springframework.dao.DataAccessException; /** * Generic DAO

Hsql - create schema if not exists in spring boot application

邮差的信 提交于 2021-01-29 03:27:04
问题 I am using embedded hsql db in my spring boot application and want to create a schema only if does not exist in the db. Assuming the schema name is XXX, I have the below single statement schema-hsql.sql file: CREATE SCHEMA XXX IF NOT EXISTS However this is faing with below stack trace: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/xxx/schema-hsql.sql]: CREATE SCHEMA XXX IF NOT EXISTS; nested exception is java

Hsql - create schema if not exists in spring boot application

微笑、不失礼 提交于 2021-01-29 03:13:46
问题 I am using embedded hsql db in my spring boot application and want to create a schema only if does not exist in the db. Assuming the schema name is XXX, I have the below single statement schema-hsql.sql file: CREATE SCHEMA XXX IF NOT EXISTS However this is faing with below stack trace: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/xxx/schema-hsql.sql]: CREATE SCHEMA XXX IF NOT EXISTS; nested exception is java

Hibernate event listener - postFlush equivalent

坚强是说给别人听的谎言 提交于 2021-01-29 03:09:59
问题 I am implementing a simple audit log functionality using hibernate event listeners. I wanted to accumulate all the changes for all entities in a transaction and handle auditing. By using hibernate interceptors approach we have postFlush() where we handle auditing of all the accumulated audit events. What is the equivalent for event listeners? I tried using 'hibernate.ejb.event.flush' event. But it invokes very beginning of the life cycle, even before onPostInsert, onPostUpdate and

How to map Postgres JSON data type in DTO and Aggentity class using Springboot and Hibernate

╄→гoц情女王★ 提交于 2021-01-29 03:01:04
问题 I have a ResponseDto class which looks like as below: public static class HealthGoalsHighlight { @ApiModelProperty(value = "Total number of eligible users") private Long totalEligibleUsers; @ApiModelProperty(value = "Total number of registered users") private Long totalRegisteredUsers; @ApiModelProperty(value = "Total number of users with atleast one goal count") private Long totalUsersWithGoal; @ApiModelProperty(value = "Top goal name selected by user") private String topGoal;

Not able to connect to MySQL - Glassfish and Hibernate

ぃ、小莉子 提交于 2021-01-29 02:50:40
问题 I have the below persistence file - <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="unit" > <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <property name=

Not able to connect to MySQL - Glassfish and Hibernate

早过忘川 提交于 2021-01-29 02:47:26
问题 I have the below persistence file - <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="unit" > <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <property name=

Hibernate isolated integration tests

為{幸葍}努か 提交于 2021-01-29 02:39:01
问题 I'm a little bit new to hibernate, so I started with simple things. According to F.I.R.S.T test principles, unit tests must be I - isolated. I'm trying to apply it to integration tests for repository layer (Hibernate\JPA) using @Transactional annotation: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = RepositoryConfig.class) @Transactional public class EmployeeRepositoryTest extends AbstractRepositoryTest { @Autowired private IEmployeeRepository employeeRepository;