Posts

Showing posts with the label hibernate

What is the configurations for enabling `ehcache replication`?

What is the configurations for enabling `ehcache replication`? I have a project that used JPA and Hibernate in DataAccessLayer with OraclDB and WebLogic application server. Also, I provided second-level-cache through ehcache as following configs: second-level-cache ehcache ehcache.xml <ehcache> <diskStore path="java.io.tmpdir"/> <defaultCache> maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"/> <persistence strategy="localTempSwap" </defaultCache> </ehcache> persistence.xml <persistence-unit name="datasource1" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>my_datasource...

REST API request using Hibernate relationships

REST API request using Hibernate relationships Rest Controller: @PostMapping("transaction") public ResponseEntity<Transaction> init(@RequestBody Transaction transactionInput) { Transaction transaction = transactionRepository.save(transactionInput); return new ResponseEntity<>(transaction, HttpStatus.OK); } Transaction Entity: @Getter @Setter @Entity @NoArgsConstructor @AllArgsConstructor @DynamicInsert @DynamicUpdate @Table(name = "transaction") public class Transaction { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false) @JoinColumn(name="currency_id") private Currency currency; Currency Entity: @Entity @NoArgsConstructor @AllArgsConstructor @Getter @Setter @DynamicInsert @DynamicUpdate @Table(name = "currency") public class Currency { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) priv...

Getting “Transaction not successfully started”

Getting “Transaction not successfully started” I got this WARN everytime I inserted / updated to DB. But my data is still saved, though. Still, I want to get rid of this from my log file. Below is my log file: [WARN] TapestryIOCModule.PerthreadManager Error invoking listener org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl@41c045: Transaction not successfully started org.hibernate.TransactionException: Transaction not successfully started at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:179) at org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.threadDidCleanup(HibernateSessionManagerImpl.java:65) at org.apache.tapestry5.ioc.internal.services.PerthreadManagerImpl.cleanup(PerthreadManagerImpl.java:128) at org.apache.tapestry5.ioc.internal.RegistryImpl.cleanupThread(RegistryImpl.java:445) at org.apache.tapestry5.ioc.internal.RegistryWrapper.cleanupThread(RegistryWrapper.java:38) at org.apache.tapestry5.TapestryFilter.doFilter(...

Hibernate Join Column only finds field with OneToMany, I need OneToOne

Hibernate Join Column only finds field with OneToMany, I need OneToOne I have a strange issue in that I can map a field on a oneToMany, but the field can't be found in a OneToOne, i.e. This works @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "task_id") public List<Voice> voices = new ArrayList<Voice>(); But this @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "task_id") private Voice voice; Gives me the error: Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'gametasks0_.task_id' in 'field list' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException (SQLError.java:686) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException (SQLError.java:663) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException (SQLError.java:653) Any clues on how I can map OneToOne via a Join Column? Why in second code snippet...

Hibernate Delayed Write

Hibernate Delayed Write I am wondering if there is a possibility of hibernate delaying its writes to the DB. I have hibernate configured for mysql. Scenarios I hope to support are 80% reads and 20% writes. So I do not want to optimize my writes, I rather have the client wait until the DB has been written to, than to return a bit earlier. My tests currently have 100 client in parallel, the cpu does sometimes max out. I need this flush method to write to DB immediately and return only when the data is written. 80% 20% On my client side, I send a write request and then a read request, but the read request sometimes returns null. I suspect hibernate is not writing to db immediately. public final ThreadLocal session = new ThreadLocal(); public Session currentSession() { Session s = (Session) session.get(); // Open a new Session, if this thread has none yet if (s == null || !s.isOpen()) { s = sessionFactory.openSession(); // Store it in the ThreadLocal varia...

LazyInitializationException with graphql-spring

LazyInitializationException with graphql-spring I am currently in the middle of migrating my REST-Server to GraphQL (at least partly). Most of the work is done, but i stumbled upon this problem which i seem to be unable to solve: OneToMany relationships in a graphql query, with FetchType.LAZY. I am using: https://github.com/graphql-java/graphql-spring-boot and https://github.com/graphql-java/graphql-java-tools for the integration. Here is an example: Entities: @Entity class Show { private Long id; private String name; @OneToMany private List<Competition> competition; } @Entity class Competition { private Long id; private String name; } Schema: type Show { id: ID! name: String! competitions: [Competition] } type Competition { id: ID! name: String } extend type Query { shows : [Show] } Resolver: @Component public class ShowResolver implements GraphQLQueryResolver { @Autowired private ShowRepository showRepository; public List...