# How to instantiate a BDM object

**URL:** <https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670>\
**Category:** Q&A\
**Created:** [18 February 2015 08:43 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670 "2015-02-18T08:43:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smoltok](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Smoltok](https://community.ofelia.com/u/Smoltok)\
**Post date:** [18 February 2015 08:43 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/1 "2015-02-18T08:43:51Z")

</div>

Hi,

I would like to use a BDM object but how to instantiate it correctly ?

I have the following error : Impossible to get data of type (name of object) with a null identifier"

Any clue ?

---

<div class="post-metadata">

**Author:** ![romain.bioteau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/romain.bioteau/32/720_2.png) [@romain.bioteau](https://community.ofelia.com/u/romain.bioteau)\
**Post date:** [19 February 2015 10:39 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/2 "2015-02-19T10:39:08Z")

</div>

An automatic instantiation of business data are done the first time a setter is called (using a Java Method operator in a operation).  
If you use a Groovy Expression, you can use the following code

myBusinessObjectDAO.newInstance('some mandatory attribute')

---

<div class="post-metadata">

**Author:** ![Smoltok](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Smoltok](https://community.ofelia.com/u/Smoltok)\
**Post date:** [18 February 2015 09:35 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/3 "2015-02-18T09:35:46Z")

</div>

Ok, maybe it 's working with a groovy script which return a new Object.

---

<div class="post-metadata">

**Author:** ![Smoltok](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Smoltok](https://community.ofelia.com/u/Smoltok)\
**Post date:** [19 February 2015 11:19 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/4 "2015-02-19T11:19:58Z")

</div>

Ok may be within the operation tab.  
However there is no newInstance method in the DAO interface.

And after init the object, I have this : javax.persistence.PersistenceException : “org.hibernate.PropertyAccessException: could not get a field value by reflection getter of TestOne.persistenceId”

Any idea ?

---

<div class="post-metadata">

**Author:** ![romain.bioteau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/romain.bioteau/32/720_2.png) [@romain.bioteau](https://community.ofelia.com/u/romain.bioteau)\
**Post date:** [19 February 2015 13:10 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/5 "2015-02-19T13:10:19Z")

</div>

What version of BonitaBPM are you using ?

---

<div class="post-metadata">

**Author:** ![Smoltok](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Smoltok](https://community.ofelia.com/u/Smoltok)\
**Post date:** [19 February 2015 13:10 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/6 "2015-02-19T13:10:52Z")

</div>

6.3.8

---

<div class="post-metadata">

**Author:** ![romain.bioteau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/romain.bioteau/32/720_2.png) [@romain.bioteau](https://community.ofelia.com/u/romain.bioteau)\
**Post date:** [19 February 2015 13:17 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/7 "2015-02-19T13:17:45Z")

</div>

ok, snippet above is available in 6.4+  
then instantiate like this :

def newBoInstance = new MyBusinessObject() newBoInstance .setMandatoryField1() newBoInstance .setMandatoryField2() return newBoInstance;

Be carefull that your script does not reference the business data you want to instantiate.  
That may lead to the above error. (eg; if your business data is called ‘testData’, don’t use testData as variable in your script)

---

<div class="post-metadata">

**Author:** ![Smoltok](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Smoltok](https://community.ofelia.com/u/Smoltok)\
**Post date:** [19 February 2015 13:37 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/8 "2015-02-19T13:37:40Z")

</div>

Ok I understand, but it doesn’t work anyway.  
I have tried also in 6.4.2  
Always the same error (like above)

---

<div class="post-metadata">

**Author:** ![Smoltok](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Smoltok](https://community.ofelia.com/u/Smoltok)\
**Post date:** [19 February 2015 14:05 UTC](https://community.ofelia.com/t/how-to-instantiate-a-bdm-object/5670/9 "2015-02-19T14:05:25Z")

</div>

Here is more complete error in 6.4.2 :

Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of FIRHDataUser.persistenceId  
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62)  
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:344)  
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4550)  
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:129)  
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:76)  
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:833)  
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:817)  
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:821)  
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:889)  
… 28 more  
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field FIRHDataUser.persistenceId to FIRHDataUser  
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)  
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)  
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)  
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(Unknown Source)  
at java.lang.reflect.Field.get(Unknown Source)  
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59)  
… 36 more
