Archive for category HIBERNATE

@SequenceGenerator allocationSize ‘duplicate key error’ issue

 

This problem solved in hibernate 5.x.x

http://stackoverflow.com/questions/30981392/sequencegenerator-allocationsize-duplicate-key-error-issue

 

Leave a comment

How to reset postgres’ primary key sequence when it falls out of sync?

How to reset postgres’ primary key sequence when it falls out of sync?

-- Login to psql and run the following
-- What is the result?
SELECT MAX(id) FROM your_table;

-- Then run...
-- This should be higher than the last result.
SELECT nextval('your_table_id_seq');

-- If it's not higher... run this set the sequence last to your highest pid it. 
-- (wise to run a quick pg_dump first...)
SELECT setval('your_table_id_seq', (SELECT MAX(id) FROM your_table));
-- if your tables might have no rows
-- false means the set value will be returned by the next nextval() call    
SELECT setval('your_table_id_seq', COALESCE((SELECT MAX(id)+1 FROM your_table), 1), false);

Leave a comment

When to use DiscriminatorValue annotation in hibernate /solving optimistic lock problem

OptimisticLock problemini cozmek icin OptimisticLockType.NONE annation kullanildi.


When to use DiscriminatorValue annotation in hibernate

To understand discriminator, first you must understand the inheritance strategies: SINGLE_TABLE, JOINED, TABLE_PER_CLASS.

Discriminator is commonly used in SINGLE_TABLE inheritance because you need a column to identify the type of the record.

Example: You have a class Student and 2 sub-classes: GoodStudent and BadStudent. Both Good and BadStudent data will be stored in 1 table, but of course we need to know the type and that’s when DiscriminatorColumn will come in.


@Entity
@DiscriminatorValue(PrdConstants.PRD)
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate =false,optimisticLock=OptimisticLockType.NONE)
public class ElectronicInfrastructureServiceElementImpl extends ProductInfrastructureServiceElementImpl {
private static final long serialVersionUID = 1L;

public ElectronicInfrastructureServiceElementImpl() {
this.setServiceType(ImsConstants.IMSICSCF);
}

public ElectronicInfrastructureServiceElementImpl newModelInstance() {
return new ElectronicInfrastructureServiceElementImpl();
}

}

, ,

Leave a comment