Saturday, January 24, 2015

org.hibernate.HibernateException: No Session found for current thread 5

I encounter this problem while I was running test

I was trying to save an object and these are the three layers in my hibernate

Entities - the ones with the metadata and the model object which actually mapped to the relations

Dao - which extends an Abstract dao, and have the most preliminary data access models.. comes with a impl

and the Service layer
I was testing the methods in the service classes and finally figured what I was missing

@Service("headerService")
@Transactional(readOnly = false)
public class HeaderServiceImpl implements HeaderService

@Transaction was missing, and these are the things which I explore during debugging

1. Setting or mutating any of the relationships
2. Going through the annotations
3. Checking the configuration files

Follow the below link 

Thursday, January 22, 2015

@Service vs @Repository and @Component in Hibernate

Can we discuss the main uses of @Repository , @Service and @Component
? This is mainly in hibernate

When to model entity objects over Embedded objects

Hi ,
Would like to know why we might possible use @Embedded over @Entity
In certain scenarios it looks like we can use or model an @Embedded object as an Entity?
1. @Embedded objects might not have a primary key, if you not willing to waste a primary key or does not stand alone, rather dependent on another identity which means does not make sense without that entity, that means its an @Embedded object rather than an Entity

http://stackoverflow.com/questions/8969059/difference-between-onetomany-and-elementcollection

http://stackoverflow.com/questions/3418683/jpa-when-to-choose-multivalued-association-vs-element-collection-mapping

Monday, January 19, 2015

Things to remember when generating relations via Hibernate

  1. Implements Serializable 
  2. override the hashcode and equals 
  3. Make sure you have the @Id with a respective columns