-
1. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 16, 2006 11:08 PM (in response to smokingapipe)I tried again and removed the inheritance part of it, still no luck in getting any objects in the collection when the object is fetched. This is with cascade=ALL. Do collections work in EJB yet? I have the EJB3 book and it has a whole section on collections but I can't get it to work in my app. Any ideas?
-
2. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 17, 2006 12:10 AM (in response to smokingapipe)I tried again with a simple uni-directional mapping.
Could someone confirm that collections are supported in EJB3? I know they worked in Hibernate 3, and that was great, but none of this seems to work within EJB 3. What is strange is there are example apps. I'll try to see if they work. -
3. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 17, 2006 12:55 AM (in response to smokingapipe)I don't get it. What is the point of having collection support in EJB if it can only save collections, but cannot make them available when the object is fetched from an EntityManager? This makes no sense. I looked back through the Seam examples, and they are good examples of esoteric things, like having conversations within conversations, but none of them deal with simple collections, leading me to wonder how I should handle entities that need to have multiple other objects "within" them? Any ideas?
-
4. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 17, 2006 2:12 AM (in response to smokingapipe)I'm even more confused. I put in a check to see what class the List was after the object was fetched. That should be some kind of proxy class, internal to EJB etc. Instead it's a plain old LinkedList. EJB isn't even trying to set a proxy or do anything with that.
So I'm not sure how to handle one-to-many relationships within my application. If EJB can save them, but not load them, that doesn't help me very much. At least Hibernate was able to both save and load them. -
5. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 17, 2006 4:36 AM (in response to smokingapipe)This is completely insane. I'm reading Enterprise JavaBeans 3.0, by Bill Burke, and it has all these examples with collections mapping, but when I actually run this within JBoss, no matter what I do, JBoss simply won't use a proxy for the Collection. What is a good approach for looking into EJB's fetching mechanism to see why it is not fetching the Collection here?
-
6. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 17, 2006 4:44 AM (in response to smokingapipe)More info: I just put a logger in my setter for the collection. Of course the setter is never called, so that means that at no point is EJB even trying to install a proxy in there. If anyone can show me an example of mapping a collection that works, and the collection is restored when the object is fetched, I would be quite amazed by that.
-
7. Re: My collection is not initializing; due to inheritance?
snau2005 Aug 17, 2006 4:53 AM (in response to smokingapipe)please post code,
do your Person and Address classes have annotaion: @MappedSuperclass ? -
8. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 17, 2006 5:04 AM (in response to smokingapipe)No, they both the abstract Person and Address classes use @Inheritance(strategy=InheritanceType.JOINED) . Will that work? Or should I switch to some other inheritance strategy?
I'm getting my code together to post it. -
9. Re: My collection is not initializing; due to inheritance?
snau2005 Aug 17, 2006 6:57 AM (in response to smokingapipe)I put here my example of 3 tables, i hope you asking of such example (in your case 2 tables)
@MappedSuperclass public class IdTable implements Serializable { @Id @GeneratedValue(strategy=GenerationType.TABLE) public Long id; } @MappedSuperclass public abstract class BasicPrimaryTable extends IdTable { @Version public Integer version; } @Entity public class SomeTable extends BasicPrimaryTable { }
if you dont want to extend some calss you need put like this:@Embeddable public class SomeClass { @Column(nullable = false, length=255) public String name; } @Entity public class SomeTable { @Embedded private SomeClass some; }
-
10. Re: My collection is not initializing; due to inheritance?
smokingapipe Aug 17, 2006 5:19 PM (in response to smokingapipe)But could someone confirm that EJB does support mapping a collection, and can load the items into the collection when the object is fetched? I see chapters on that in this book but I don't see any evidence that it is possible.
I notice that when I persist my Customer object, the collection is never changed. Upon persistence, the collection should be converted into a proxy, but this obviously does not happen, leading me to wonder if EJB is even capable of doing that. If I were programming it, I would have the EntityManager.persist() method go through and call setters on all the objects it is persisting to replace their Collections with EJB proxies, but it ignores them. Either EJB doesn't support that use, or there is a bug in the EJB implementation. -
11. Re: My collection is not initializing; due to inheritance?
snau2005 Aug 18, 2006 3:09 AM (in response to smokingapipe)there is fetch strategies:
FetchType.EAGER or FetchType.LAZY, default i think lazy@OneToMany(mappedBy = "field", fetch=FetchType.EAGER) @Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN}) public List<SomeClass> somoes;