cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem creating atomic type

Former Member
0 Likes
1,641

I was trying to create an atomic type in my custom extension.

&ltatomictype class="com.myextension.somepackage.CustomAtomicType" extends="java.lang.Object" autocreate="true" generate="false"/>

I creating a POJO for my atomic type with constructor in my custom extension

public class CustomAtomicType implements Serializable { private final String attribute1;

private final String attribute2;

public CustomAtomicType (String attribute1,String attribute2) { super(); this.attribute1= attribute1; this.attribute2= attribute2; } //Custom methods

}

But when I am using this atomic type in Customer Model ,the model generation is failing as it is not able to find the dependency of my Custom Atomic Type in platform/gensrc where the Customer Model is getting generated.

&ltattribute autocreate="true" generate="true" qualifier="customAttribute" type="com.myextension.somepackage.CustomAtomicType"> &ltmodifiers read="true" write="true" search="true" optional="true" /> &ltpersistence type="property" /> < /attribute>

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Likes

Couple of years ago it was not possible, add new Atomic type

sharada1234
Explorer
0 Likes

Can you suggest a solution for this.Even I am facing the same issue while adding custom atomic types.No .class file generated in platform/bootstrap/gensrc

mpern
Product and Topic Expert
Product and Topic Expert
0 Likes

Try defining your atomic type class using the mycustomextension-beans.xml, this seems how it is done in the platform.

EDIT

Just tested it, it works!

training-beans.xml

 <bean class="org.training.data.SomeDTO">
     <property name="id" type="String"/>
     <property name="flag" type="boolean"/>
 </bean>

training-items.xml

 <itemtype code="Product" autocreate="false" generate="false">
     <attributes>
         <attribute qualifier="someProperty" type="org.training.data.SomeDTO">
             <persistence type="property" />
         </attribute>
     </attributes>
 </itemtype>

After ant clean all and update running system, the property is available.

Warning all the problems as mentioned in the previous question linked by still apply!

  • you have no flexible search support

  • Backoffice etc probably won't be able to display the value

  • You now have to worry about Java Object Serialization / Deserialization, because that's how the values are stored in the DB. Changing the DTO class may break stuff

  • Changing nested properties doesn't mark the model as dirty -> changes are not saved on modelService.save

     ProductModel product = ...
    
       SomeDTO dto = new SomeDTO()
       dto.setId("value")
       product.setSomeProperty(dto)
       // works, change is saved
       modelService.save(product) 
    
       dto.setId("new value")
       // does NOT work, change is NOT saved
       modelService.save(product) 
    
       dto = new SomeDTO()
       dto.setId("new value")
       // change detected because new object instance?
       product.setSomeProperty(dto)
       // change is correctly saved
       modelService.save(product)
    
    

That said, I think having the option to return arbitrary objects is great for Dynamic Attributes and maybe for some specific use cases were you may want to precompute and cache values in the database.

But you have to be very sure what you are doing, and I doubt this is officially supported.

geffchang
Active Contributor
0 Likes

Are you using Ee? Make sure that the custom project sees the platform project (check the Java Build path). Also, make sure that you have refreshed the entire Ee workspace.

Former Member
0 Likes

Hi its not about ee. I am getting build failure as the generated model classes are in platform and my atomic type is in my custom extension.

geffchang
Active Contributor
0 Likes

Did you extend CustomerModel or add new attributes to it, and is this new attribute the new AtomicType?

Former Member
0 Likes

I didnot extend the Customer Model. I added a new attribute which is of atomic type to the existing Customer Model.