I have User class and BattleReportILogItem class. This class (User, BattleReportILogItem) are #Entity.
User have 0..N BattleReportILogItem.
USER
#Entity
#Table(name = DomainConstant.TABLE_USER)
public class User implements Serializable {
#Id
#Column(name = DomainConstant.DOMAIN_USER_ID)
#GeneratedValue
private Long userId;
#ManyToMany(cascade = {CascadeType.ALL})
#JoinTable(name = DomainConstant.VIEW_USER_BATTLE_LOGS, joinColumns = {
#JoinColumn(name = DomainConstant.DOMAIN_USER_ID)}, inverseJoinColumns = {
#JoinColumn(name = DomainConstant.DOMAIN_BATTLE_REPORT_ID)})
private Set<BattleReportILogItem> setOfBattleLogs = new HashSet<>();
....(other stuff, get and set methods...)
BattleReportILogItem
#Entity
#Table(name = DomainConstant.TABLE_BATTLE_REPORT)
public class BattleReportILogItem implements Serializable {
#Id
#GeneratedValue
#Column(name = DomainConstant.DOMAIN_BATTLE_REPORT_ID)
private Long BattleReportILogItemId;
#ManyToMany(mappedBy = "setOfBattleLogs")
private Set<User> setOfBattleLogs = new HashSet<>();
....(other stuff, get and set methods...)
The problem is, that I load User program loads all data in private Set<BattleReportILogItem> setOfBattleLogs = new HashSet<>();. This mean 1 000 000 000 items in my set setOfBattleLogs. I don't want load data to this set. For load data i have BattleReportLogItemDao DAO.
Is there any solution how to NOT LOAD DATA to my set?
I hope, you understand me... :-))
Thank you for your help.
EDIT persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="com.donutek" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.validator.apply_to_ddl" value="true" />
<property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.timeout" value="300"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="300"/>
</properties>
</persistence-unit>
</persistence>
EDIT 2:
For load user I am using the code:
#Override
public User findByEmail(String email) {
TypedQuery<User> q = em.createQuery("SELECT u FROM " + User.class.getSimpleName() + " u WHERE u.email = :uemail", User.class);
q.setParameter("uemail", email);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
You can use the parameter fetchtype Lazy. Now your strategy seems to be Eager.
Related
create tables from Java in database on Microsoft SQL Server 2012. All tables are created, except one table. I'm using JPA and there is my persistence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<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="teknikPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/teknikNDataSource</jta-data-source>
<class>com.royken.entities.Bloc</class>
<class>com.royken.entities.Elements</class>
<class>com.royken.entities.Organes</class>
<class>com.royken.entities.SousOrganes</class>
<class>com.royken.entities.Utilisateurs</class>
<class>com.royken.entities.Zone</class>
<class>com.royken.entities.Reponse</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<property name="eclipselink.logging.level" value="OFF"/>
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.query-results-cache" value="false"/>
<!-- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.engine.transaction.jta.platform.internal.SunOneJtaPlatform" />
<property name="hibernate.transaction.factory_class" value="org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.classloading.use_current_tccl_as_parent" value="false"/>-->
<!--<property name="javax.persistence.schema-generation.database.action" value="create"/> -->
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
This is how I define my classes :
#Entity
#XmlRootElement(name = "elements")
#Table(name = "ELEMENTS")
#XmlAccessorType(XmlAccessType.FIELD)
public class Elements implements Serializable {
private static final long serialVersionUID = 1L;
#OneToMany(mappedBy = "elements")
private List<Reponse> reponses;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "ID")
private Long id;
#Version
#Column(name = "VERSION")
private int version;
#Column(name = "NOM")
private String nom;
#Column(columnDefinition = "tinyint(1) default true", name = "HASBORNS")
private boolean hasBorns;
#Column(columnDefinition = "tinyint(1) default true", name = "CRITERIAALPHA")
private boolean criteriaAlpha;
}
I have defined 7 tables like that, but only 6 tables are created, Elements tables is not created. When I change the datasource by using a mysql database (without changing any part of code), all my tables are well created.
What can be the issue ?
The image bellow shows the result in SQL server, Elements table is not present.
In your persistence.xml Use :
<property name="eclipselink.deploy-on-startup" value="true" />
In your code, you may use:
import javax.ejb.Stateless;
import entity.userEntity;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
Look for EntityManager
#PersistenceContext
private EntityManager entityManager;
and then use it like :
Query query = entityManager.createQuery("SELECT e FROM Elements e WHERE e.id= :idValue");
query.setParameter("idValue", 1);
Elements elements = null;
try {
elements = (Elements) query.getSingleResult();
} catch (NoResultException ex) {
ex.printStackTrace();
}
You may refer to this
If that too doesn't help look here
I found the solution to my problem. Entity table was not created because SQL Server does not accept true as default value for hasborns and criteriaalpha. Also, it does not now the size to allocate to tinyint type. So it throws an error during table creation. To solve this issue, I replaced:
#Column(columnDefinition = "tinyint(1) default true", name = "HASBORNS")
private boolean hasBorns;
#Column(columnDefinition = "tinyint(1) default true", name = "CRITERIAALPHA")
private boolean criteriaAlpha;
with:
#Column(columnDefinition = "BIT default 1", name = "HASBORNS", length = 1)
private boolean hasBorns ;
#Column(columnDefinition = "BIT default 1", name = "CRITERIAALPHA", length = 1)
private boolean criteriaAlpha ;
And it worked
I've read Do I need <class> elements in persistence.xml? and How to auto detect entities in JPA 2.0 and followed their tag useage in my persistence.xml, but Entitys are not being auto detected by Hibernate. When I remove the <class> tag this no longer works and I get a MappingException. For some reason I can't seem to enable auto detection. NOTE this is a stand-alone hibernate application (shouldn't matter as far as I know). I have this example:
Persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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="Test_Project" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.gmail.physicistsarah.gradletestproject.core.Person</class>
<!--Exclude unlisted class detection-->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test_project_db?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="javax.persistence.schema-generation.database.action" value="none"/>
<!--<property name="hibernate.show_sql" value="true"/>-->
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
Person:
package com.gmail.physicistsarah.gradletestproject.core;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* #author Sarah Szabo
*/
#Entity
#Table(name = "Person")
public class Person {
#Id
#GeneratedValue
#Column(name = "Person_ID")
private final int id = 0;
#Column(name = "First_Name", nullable = false)
private final String firstName;
#Column(name = "Last_Name", nullable = false)
private final String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
Init (Main class):
package com.gmail.physicistsarah.gradletestproject.core;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class Init {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("Test_Project");
EntityManager manager = factory.createEntityManager();
Session session = manager.unwrap(Session.class);
Transaction transaction = session.getTransaction();
transaction.begin();
session.saveOrUpdate(new Person("Carl", "Gauss"));
session.saveOrUpdate(new Person("Benoit", "Mandelbrot"));
transaction.commit();
factory.close();
}
}
You should try using HibernatePersistenceProvider and remove the <class> element from the persistence.xml.
Also remove <exclude-unlisted-classes> since it is not applicable to Java SE persistence units as per the official schema definition http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd
<?xml version="1.0" encoding="UTF-8"?>
<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="Test_Project" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<shared-cache-mode>ALL</shared-cache-mode>
<validation-mode>AUTO</validation-mode>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test_project_db?zeroDateTimeBehavior=convertToNull" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
I noticed that you are inter mixing JPA code with Hibernate code. If you're using JPA then try to stick to JPA.
Use the following code after creating the EntityManager:
EntityTransaction tran = manager.getTransaction();
tran.begin();
try {
Person savedPerson1 = manager.merge(new Person("Carl", "Gauss"));
Person savedPerson2 = manager.merge(new Person("Benoit", "Mandelbrot"));
tran.commit();
} catch (Exception e) {
tran.rollback();
}
manager.close();
factory.close();
Remember to access the returned entity from EntityManager.merge() call to access any auto-generated fields.
You should use the following Maven POM dependencies for the above to work as expected in a Java SE environment:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
I'm new in kundera. My usecase is with Kundera and MySQL. I'm saving an entity using spring's CrudRepository. ID in that entity is AUTO generated.
Kundera is saving that object successfully in DB. but returning wrong ID. and if I'm using that Id to find the data from DB , it returns null.
Could you please let me know if I'm missing any thing.
Entity Class :
#Entity
#Table(name = "REQUEST_DETAILS")
public class RequestDetails {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "ID")
protected long id;
#Column(name = "REQUEST_STATUS", nullable = false)
private String requestStatus;
// getter setter
}
MAIN class :
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/spring/jpa-config.xml");
RequestDetailsRepository repository = context.getBean(RequestDetailsRepository.class);
RequestDetails requestDetails = new RequestDetails();
requestDetails.setRequestStatus("STARTED");
RequestDetails updatedRequest = repository.save(requestDetails);
System.out.println("request id : " + updatedRequest.getId()); // returning wrong ID (probably hashcode of that object)
// Do some operation
RequestDetails details = repository.findOne(updatedRequest.getId()); // returning NULL
}
CRUD Repository :
public interface RequestDetailsRepository extends org.springframework.data.repository.CrudRepository<RequestDetails, Long> {
}
jpa-config.xml :
<beans>
<context:component-scan base-package="com.example.project" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceUnit"/>
</bean>
<jpa:repositories base-package="com.example.project.repository"/>
</beans>
Persistence.xml :
<persistence>
<persistence-unit name="persistenceUnit">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.client.lookup.class" value="com.impetus.client.rdbms.RDBMSClientFactory" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect" />
<property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:jtds:sqlserver://10.127.127.215:1433;databaseName=myDB" />
<property name="hibernate.connection.username" value="user" />
<property name="hibernate.connection.password" value="password" />
<property name="hibernate.current_session_context_class"
value="org.hibernate.context.ThreadLocalSessionContext" />
</properties>
</persistence-unit>
</persistence>
I want to do a pretty simple thing but can't get it to work.
I have ab entity Game and an Entity Player. Every Game should have two foreign keys from Players. And it works, but there is one catch: I cant assign the same foreign key from Player to multiple Game-entities. Where is this constraint coming from, and how can I tell him to not do that?
I'm using Hibernate and JPA. My persistence.xml looks like this:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence" version="1.0">
<persistence-unit name="PlayerService" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.username" value="********"/>
<property name="hibernate.connection.password" value="********"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://********"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
I'm getting the entitymanager per:
util = new JPAUtil();
emf = Persistence.createEntityManagerFactory("PlayerService");
em = emf.createEntityManager();
em.getTransaction().begin();
in my Games-Entity:
#ElementCollection(targetClass=Player.class)
private Collection<Player> player;
and there is Player-Entity.
Am I doing this entirely wrong?
#Entity
public class Game {
#Id
int gameid;
#OneToMany(mappedBy="game")
private Collection<TestPlayer> test;
}
#Entity
public class TestPlayer {
#Id
int id;
#ManyToOne
#JoinColumn(name="gameid")
private Game game;
}
I'll try an OneToMany relationship instead of ElementCollection.
I think that in an ElementCollection the elements (Player) belongs to the Game and therefore Hibernate doesn't let you assign it to multiple Games
in your Game Entity:
#OneToMany(mappedBy="game")
private Collection<Player> player;
in your Player entity:
#ManyToOne
#JoinColumn(name="game_id")
private Game game;
for reference: http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html#entity-mapping-association
I'm trying to get EHCache working within my app. First thing I did was adding maven dependency:
pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate-version}</version>
</dependency>
So far so good, now within my application root-context.xml (SessionFactory is defiend in roout because of OpenSessionInView filter) I added MBean for Hibernate statistics from jConsole and full definition of my sessionFactory:
root-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="jmxExporter"
class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="Hibernate:type=statistics">
<ref local="statisticsBean"/>
</entry>
</map>
</property>
</bean>
<bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled" value="true"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="namingStrategy" class="com.execon.OracleNamingStrategy"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.OracleDriver"/>
<property name="jdbcUrl" value="jdbc:oracle:thin:#127.0.0.1:1521:orcl"/>
<property name="user" value="xxx"/>
<property name="password" value="xxx"/>
<property name="maxPoolSize" value="10"/>
<property name="maxStatements" value="0"/>
<property name="minPoolSize" value="5"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="namingStrategy" ref="namingStrategy"/>
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
<property name="packagesToScan" value="com.execon.models"/>
</bean>
</beans>
Time to define hibernate.cfg.xml and ehcache file, so here they are:
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</property>
<property name="hibernate.generate_statistics">true</property>
</session-factory>
</hibernate-configuration>
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="java.io.tmpdir"/>
<defaultCache
eternal="false"
maxElementsInMemory="1000"
maxElementsOnDisk="10000"
overflowToDisk="true"
diskPersistent="true"
timeToLiveSeconds="300"
/>
</ehcache>
Everything is working great, so now its time to define some Service to test cache, so I did:
#Service
#Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
#Transactional(readOnly = true)
public class MyService
{
#Autowired
private SessionFactory sessionFactory;
#SuppressWarnings("unchecked")
#Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public List<SettlementModelGroup> getModelGroups()
{
List<SettlementModelGroup> list = new ArrayList<SettlementModelGroup>();
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery( "from SettlementModelGroup" );
list.addAll( query.list() );
return list;
}
}
As you can see, this basic method alwas returns me same list. So I'm checking hibernate statistics and:
secondLevelCacheHitCount 0
secondLevelCacheMissCount 0
secondLevelCachePutCount 0
Rest of the statistics on screen:
Link if too small: http://s11.postimage.org/yfg9h6m83/image.jpg
So whats wrong, did I miss something (obvious)? Or am I going completly wrong way?
EDIT
SettlementModelGroup Entity (tried also CacheConcurrencyStrategy.READ_WRITE)
#Entity
#Table(name = "MODEL_GROUP")
#Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class SettlementModelGroup implements Serializable
{
#Id
#GeneratedValue(generator = "MODEL_GROUP_SEQ", strategy = GenerationType.SEQUENCE)
#SequenceGenerator(name = "MODEL_GROUP_SEQ", sequenceName = "SEQ_MODEL_GROUP_MODEL_GROUP_ID")
#Column(name = "MODEL_GROUP_ID", nullable = false)
private Integer modelId;
#Column(name = "NAME", nullable = false)
private String modelGroupName;
#Column(name = "DESCRIPTION", nullable = false)
private String modelGroupDescription;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "MODEL_GROUP_TYPE_ID", nullable = false)
private SettlementModelGroupType settlementModelGroupType;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "PERIOD_TYPE_ID", nullable = false)
private PeriodType periodType;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "DOMAIN_ID")
private Domain domain;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "OWNER_ID", nullable = false)
private User user;
#OneToMany(fetch = FetchType.LAZY, mappedBy = "modelId")
#Cascade(CascadeType.ALL)
private List<SettlementModel> settlementModels;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "STATUS_ID")
private Status status;
//getters and setters here
}
Put #Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) on SettlementModelGroup (your domain entity) not the service method.
Also see this link. Depending on your version of EhCache (2.4.3.?) you might have to use CacheConcurrencyStrategy.READ_WRITE.