Showing posts with label hibernate. Show all posts
Showing posts with label hibernate. Show all posts

Tuesday, 7 June 2016

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column ' ' cannot be null

Let us check scenario of hibernate.
solution :
1.check entity  mapping with table.
2. check the primary key and foreign key relationship.
3. primary key cannot be "not null" in table, it can be null in other table. 

Tuesday, 24 May 2016

WARN (SqlExceptionHelper.java:233) - Unknown column 'xxx' in 'field list'

 WARN  (SqlExceptionHelper.java:233) - Unknown column 'EditedOn' in 'field list'

Solution :
1) In hibernate check the entity class.
2) In table check the column names.
3) Compare both the entity and column name.
4.Caused due to spelling mistake.

Thursday, 19 May 2016

When to use detached criteria and criteria.

When to use detached criteria and criteria.

detached criteria : if we want to create a query wihout any session
Ref : Stackoverflow

another alternative is

If you are using Spring and choose to use HibernateTemplate, it doesn't provide createCriteria() method.

Ref :  spring

Thursday, 12 May 2016

Write operations are not allowed in read-only mode (FlushMode.MANUAL)


org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
at org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)
at org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:620)
at org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:617)
Below of the piece of code worked for me. Added @Transactional annotation where i was performing insert operation
@Transactional
public void sendVoice(VoiceUser voiceUser) {
                    feedSendVoice.save(voiceUser)
 }