Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:32:35+00:00 2026-06-03T00:32:35+00:00

When I persist new created entity by JPA-Hibernate, some setter methods are called. Why?

  • 0

When I persist new created entity by JPA-Hibernate, some setter methods are called. Why? Hibernate must read all properties, but why values (not ID) are set back to entity?

CODE

public void run(){
    System.out.println("Before transaction");
    loadInitialData();
    System.out.println("After transaction");
}

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
private void loadInitialData() {
    Contract contract = new Contract();
    contract.setAmountMonth(new BigInteger("42"));
    System.out.println("Before persist");
    entityManager.persist(contract);
    System.out.println("After persist");
}

OUTPUT

Before transaction
Contract.setAmountMonth null -> 42              ---- OK, my call
Before persist
Contract.getAmountMonth 42 -> 42
Contract.setAmountMonth 42 -> 42                !!!!!! WHY?
After persist
Contract.getAmountMonth 42 -> 42
Contract.getAmountMonth 42 -> 42
Contract.getAmountMonth 42 -> 42
After transaction

SPRING-CONFIGURATION

   <persistence-unit name="org.drools.persistence.jpa.local">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>jdbc/dataSource</non-jta-data-source>
        <mapping-file>META-INF/orm.xml</mapping-file>
        <class>org.drools.persistence.info.SessionInfo</class>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.transaction.flush_before_completion" value="true" />
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
        </properties>
    </persistence-unit>

ENTITY

public class Contract  {
    private volatile long ceresID;
    private volatile BigInteger amountMonth;

    public long getCeresID() {
        return ceresID;
    }
    public void setCeresID(long ceresContractID) {
        this.ceresID = ceresContractID;
    }

    public BigInteger getAmountMonth() {
        System.out.println("Contract.getAmountMonth " + this.amountMonth + " -> " + amountMonth);
        return amountMonth;
    }
    public void setAmountMonth(BigInteger amountMonth) {
        System.out.println("Contract.setAmountMonth " + this.amountMonth + " -> " + amountMonth);
        this.amountMonth = amountMonth;
    }
}

ENTITY-MAPPINGS

<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
    <entity class=".....Contract" access="PROPERTY">
        <attributes>
            <id name="ceresID" access="FIELD">
                <generated-value strategy="AUTO"/>
            </id>
        </attributes>
    </entity>
</entity-mappings>

Stacktrace of second setAmountMonth

at Contract.setAmountMonth(Contract.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:583)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:229)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3822)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:299)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at $Proxy29.persist(Unknown Source)
at DBPersister.persistOrMerge(DBPersister.java:93)

LIBRARY VERSIONS

  • java 1.6.0_29
  • hibernate 3.6.0
  • spring 3.0.5
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:32:38+00:00Added an answer on June 3, 2026 at 12:32 am

    With this stacktrace answer can be easily found in Hibernate source.

    In order to save an object Hibernate extracts the state from it. That extracted state can be changed during save by custom Interceptor or to assign value to the version field. If state have been changed, Hibernate writes it back to the object (all fields, it doesn’t track which fields have been changed), that’s what you observe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to persist my entity with ManyToMany relation. But i have some problem
I am attempting to persist/merge a brand new object graph through jpa but it
i am trying to persist two entities(with one to many relationship) using jpa but
JPA + Hibernate I'm using this code to create a new AvatarAttributeOwnership ( AAO
I'm new to EJB 3 and the JPA. I've created a datasource in the
I am using JPA to persist data. I am new to whole of Java-ee
I wish to persist some extra data in a many-to-many relationship by having some
I am trying to persist an Entity with a @Lob annotated String field. The
I've mapped two entities using JPA (specifically Hibernate). Those entities have a one-to-many relationship
I have a JPA/Spring application that uses Hibernate as the JPA provider. In one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.