Can someone give me an example of how to work with transient collections? What I want is a Collection<Item> that's filled by an action. There is no need for this result to be persisted, it's just info for the user. In this case Item is a persistent class but I could use a plain bean with a couple of properties.
I've tried various things (@Transient on property and getter, declaring the collection field as transient etc.) and the collection always appears empty. I can see the action setting the collection property but nothing shows up when calling refreshCollections() on the view.
I noticed you can't set this property with setValue() on the view but it is shown in the UI so I have probably done something wrong.
Thanks,
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Define the collection without @OneToMany. Fill the collection by code and then inject the container object (the entity or transient object) into the view with getView().setModel(myContainerObject). If it does not work, put here the code of your entity and your action.
Help others in this forum as I help you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OpenXava for entity collection (those without @ElementCollection) does not use the getter of the class but it get the data directly from database using JPA. In this way we can paginate, filtering and ordering. So if you use @ElementCollection OpenXava will get the data from the getter.
Help others in this forum as I help you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just out of interest should @ListProperties work with this approach? It doesn't really matter as I'll just define the bean to have the ones I want but I got the exception below when I added it.
ust out of interest should @ListProperties work with this approach?
@ListProperties works with element collections.
org.openxava.util.XavaException: collection-view for chosen is already defined in view chosen of
Attach here the complete code of the class, I'll examine it to see where the problem is.
Is there any chance this stopped working in 6.4.2?
I just try the example I use to solve your problem and it works perfectly with 6.4.2. Maybe the updated process is incomplete. Do you follow all the steps? Including the updateOX ant task execution?
Help others in this forum as I help you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I got the exception when I switched from a transient Bean class to making it a Collection<Item> where Item is an entity and has views defined. I switched back to a bean so this is no longer a problem.
I've solved my other problem, for some reason the action was extending ViewDetailAction. I changed it back to ViewBaseAction and it started working. I don't think it's related to 6.4.2.
Thanks,
Martin
Last edit: Martin Smith 2020-11-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Can someone give me an example of how to work with transient collections? What I want is a
Collection<Item>
that's filled by an action. There is no need for this result to be persisted, it's just info for the user. In this caseItem
is a persistent class but I could use a plain bean with a couple of properties.I've tried various things (
@Transient
on property and getter, declaring the collection field astransient
etc.) and the collection always appears empty. I can see the action setting the collection property but nothing shows up when callingrefreshCollections()
on the view.I noticed you can't set this property with
setValue()
on the view but it is shown in the UI so I have probably done something wrong.Thanks,
Martin
Hi Martin:
Define the collection without @OneToMany. Fill the collection by code and then inject the container object (the entity or transient object) into the view with getView().setModel(myContainerObject). If it does not work, put here the code of your entity and your action.
Help others in this forum as I help you.
Hi,
Thanks but I still see no items in the collection, must be doing something wrong. The code below is a minimal version of what I have.
Martin
In the entity class
Template
, which is where I want to show the results:Plus a getter and setter. The
Thing
class is just a bean with a couple of properties.In the action (just an example for testing purposes):
Last edit: Martin Smith 2020-11-11
Hi Martin:
Add @ElementCollection annotation and it will work with your code above. Thus;
OpenXava for entity collection (those without @ElementCollection) does not use the getter of the class but it get the data directly from database using JPA. In this way we can paginate, filtering and ordering. So if you use @ElementCollection OpenXava will get the data from the getter.
Help others in this forum as I help you.
Thanks a lot, that works exactly as I wanted.
Just out of interest should
@ListProperties
work with this approach? It doesn't really matter as I'll just define the bean to have the ones I want but I got the exception below when I added it.Martin
Is there any chance this stopped working in 6.4.2? I just updated and can no longer see anything after populating the list.
Thanks,
Martin
Hi Martin:
@ListProperties works with element collections.
Attach here the complete code of the class, I'll examine it to see where the problem is.
I just try the example I use to solve your problem and it works perfectly with 6.4.2. Maybe the updated process is incomplete. Do you follow all the steps? Including the updateOX ant task execution?
Help others in this forum as I help you.
Hi,
I got the exception when I switched from a transient Bean class to making it a
Collection<Item>
whereItem
is an entity and has views defined. I switched back to a bean so this is no longer a problem.I've solved my other problem, for some reason the action was extending
ViewDetailAction
. I changed it back toViewBaseAction
and it started working. I don't think it's related to 6.4.2.Thanks,
Martin
Last edit: Martin Smith 2020-11-17