I am developing an application using Jboss AS 7, CDI, JPA, and some other resources bundled.
My question is: When I create a project in Eclipse using the maven-jboss-webapp-archetype it generates some files, which I have been extensively studying and trying to get along with. The problem is that sometimes I see myself a little bit confused whether I am using Hibernate resources or JPA resources.
Second question: When I use multiple @OneToMany relationships in the same Entity I notice two behaviors:
a) Without specifying EAGER type for Fetch, it deploys the application but when I try to use the list it gives me the LazyInitializationException error so vastly discussed here.
b) When I specify Eager for the FetchType on the @*ToMany relationship it just doesnt deploys the application. It gives me the error: Cannot instantiate multiple bags.
Here is the problematic piece of code:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "teamUser" , fetch = FetchType.EAGER)
private Collection<Users> usersCollection;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "teamRanking" , fetch = FetchType.LAZY)
private Collection<Ranking> rankingCollection;
@NotNull
@OneToMany(cascade = CascadeType.ALL, mappedBy = "teamModality" , fetch = FetchType.LAZY)
private Collection<Modality> modalitiesCollection;
public Teams() {
}
public Teams(Long id_team , String name) {
this.id = id_team;
this.name = name;
}
I have been reading about this and people told me that JPA does not support FetchType.EAGER for multiple realtionships in the same Entity. But I need to use multiple relationships in this entity in specific. I don't know what to do anymore, because I have tried several approaches, Lazy fetching, and all of them present some kind of issue. For example, if I leave only one FetchType.EAGER in the class then it deploys my app but it doesn't runs properly because when I try to fetch a List from the database it gives me the error: LazyInitializationException, and when I try to put all of them using the FetchType.EAGER it just doesnt deploy because it gives the error: Cannot instantiate multiple bags.
So my issues here are related to:
1) Maven-jboss-webapp-archetype uses hibernate or jpa or both? 2) How can I attack this problem of using multiple @OneToMany relationships in an Entity? And although I know that fetching eagerly the Collections in the model is not the best approach because when the system grows I will probably have performance issues right? So how can I properly work with Lazy loading?