on 2018 Nov 28 1:17 PM
Given the following itemtype definition:
<itemtype code="BaseSite" autocreate="false" generate="false">
<description>Extending BaseSite type with additional attributes.</description>
<attributes>
<!-- Other properties omitted -->
<attribute qualifier="defaultPromotionGroup" type="PromotionGroup">
<description>The default promotion group for the site.</description>
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
the file BaseSiteModel.java will be generated:
public class BaseSiteModel extends ItemModel
{
public final static String _TYPECODE = "BaseSite";
/* Other properties omitted */
public static final String DEFAULTPROMOTIONGROUP = "defaultPromotionGroup";
@Accessor(qualifier = "defaultPromotionGroup", type = Accessor.Type.GETTER)
public PromotionGroupModel getDefaultPromotionGroup()
{
return getPersistenceContext().getPropertyValue(DEFAULTPROMOTIONGROUP);
}
}
The generated class has no property of type PromotionGroupModel, only a static final String which will be used by the getter to return an instance of type PromotionGroupModel.
The question: Is there any way to have hybris generate a real association property like the following?
private PromotionGroupModel promotionGroup;
That way the generated java class would look like:
public class BaseSiteModel extends ItemModel
{
public final static String _TYPECODE = "BaseSite";
/* Other properties omitted */
public static final String DEFAULTPROMOTIONGROUP = "defaultPromotionGroup";
private PromotionGroupModel promotionGroup;
@Accessor(qualifier = "defaultPromotionGroup", type = Accessor.Type.GETTER)
public PromotionGroupModel getDefaultPromotionGroup()
{
return promotionGroup;
}
}
Request clarification before answering.
It once was the way you ask for! Having the a real object property also has the advantage to actually see the model fields in a debugger as how it is now you don't see the fields.
The hybris models are not real pojo. You see the members of the model only from the getter/setter pair. The real values are in a hashmap in the context object. But not all of them, only the ones you have accessed.
Why hybris changed from real object members to a proprietary hash map one (or at least I) can only speculate.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can customize model generation, but what you are looking for is not supported.
Only the following are supported:
exclude an entire type (including all subtypes) from the generation
exclude an attribute from the Model generation process
specify a constructor to be generated
add alternative getter and setter methods for an attribute
I assume it's designed this way because it needs to get the values through the persistence context.
Reference: Models
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your answer. I can't help but only sigh in frustration that it's been implemented this way. It's thwarting the help the language syntax can offer.
Just for my own note, why not something like this?:
@Accessor(qualifier = "defaultPromotionGroup", type = Accessor.Type.GETTER)
public PromotionGroupModel getDefaultPromotionGroup()
{
if (promotionGroup == null) {
promotionGroup = getPersistenceContext().getPropertyValue(DEFAULTPROMOTIONGROUP);
}
return promotionGroup;
}
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.