java - HIbernate - Many to Many - Nested c:foreach -
i'm trying run nested c:loop
in following. before page loads, list itemsextrascat
objects itemsextrascatservice.getextrascatbyiditems(item)
. no problem here, right number of results. however, nested loop not displaying properly. not sure if hibernate issue or jstl.
jsp
<c:foreach var="itemsextrascat" items="${itemsextrascat}"> <th><c:out value="${itemsextrascat.extrascat.name}"></c:out> </th><br> <table> <c:foreach var="extras" items="${itemsextrascat.extrascat.extras}"> <tr><c:out value="${extras.name}"></c:out></tr> </c:foreach> </table> </c:foreach>
which returns
fruit overy easy syrups on medium breakfast additions sunny side
so category titles correct, extras 1) incorrect item , extrascat , 2) not listing extras under category. pretty sure how hibernate calling object i'm @ loss.
extrascat.java
@entity @table(name = "extrascat") public class extrascat implements serializable { private static final long serialversionuid = 8644201177004602944l; @id private int idextrascat; private string name; @manytomany(cascade = { cascadetype.all }, mappedby = "extrascat") private set<items> items = new hashset<items>(); @onetomany(fetch = fetchtype.eager, cascade = cascadetype.all) @joincolumn(name = "idextras") private set<extras> extras; // constructors public extrascat() { } public extrascat(int idextrascat, string name, set<items> items, set<extras> extras) { this.idextrascat = idextrascat; this.name = name; this.items = items; this.extras = extras; } // getters , setters public int getidextrascat() { return idextrascat; } public void setidextrascat(int idextrascat) { this.idextrascat = idextrascat; } public string getname() { return name; } public void setname(string name) { this.name = name; } public set<items> getitems() { return items; } public void setitems(set<items> items) { this.items = items; } public set<extras> getextras() { return extras; } public void setextras(set<extras> extras) { this.extras = extras; } }
items.java
@entity @table(name = "items") public class items implements serializable { private static final long serialversionuid = -3607451001182083512l; @id @generatedvalue private int iditems; @manytoone @joincolumn(name = "idcategories") private categories categories; @size(min = 1, max = 35, groups = { persistencevalidationgroup.class, formvalidationgroup.class }) private string name; @size(min = 0, max = 100, groups = { persistencevalidationgroup.class, formvalidationgroup.class }) private string description; private double priceincents; private int hidden; @ordercolumn @manytomany(cascade = {cascadetype.remove}, fetch = fetchtype.lazy) @jointable(name="itemsextrascat", joincolumns={@joincolumn(name="iditems")}, inversejoincolumns={@joincolumn(name="idextrascat")}) private set<extrascat> extrascat = new hashset<extrascat>(); // constructors public items() { } public items(int iditems, categories categories, string name, string description, double priceincents, int hidden, set<extrascat> extrascat) { this.iditems = iditems; this.categories = categories; this.name = name; this.description = description; this.priceincents = priceincents; this.hidden = hidden; this.extrascat = extrascat; } // getters , setters public int getiditems() { return iditems; } public void setiditems(int iditems) { this.iditems = iditems; } public categories getcategories() { return categories; } public void setcategories(categories categories) { this.categories = categories; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public double getpriceincents() { return priceincents; } public void setpriceincents(double priceincents) { this.priceincents = priceincents; } public int ishidden() { return hidden; } public void sethidden(int hidden) { this.hidden = hidden; } public set<extrascat> getextrascat() { return extrascat; } public void setextrascat(set<extrascat> extrascat) { this.extrascat = extrascat; } public int gethidden() { return hidden; } }
itemsextrascat.java
@entity @table(name = "itemsextrascat") public class itemsextrascat implements serializable { private static final long serialversionuid = 7640244484584804821l; @id @generatedvalue private int iditemsextrascat; @manytoone @joincolumn(name = "iditems") private items items; @manytoone @joincolumn(name = "idextrascat") private extrascat extrascat; // constructors public itemsextrascat() { } public itemsextrascat(int iditemsextrascat, items items, extrascat extrascat) { this.iditemsextrascat = iditemsextrascat; this.items = items; this.extrascat = extrascat; } // getters , setters public int getiditemsextrascat() { return iditemsextrascat; } public void setiditemsextrascat(int iditemsextrascat) { this.iditemsextrascat = iditemsextrascat; } public items getitems() { return items; } public void setitems(items items) { this.items = items; } public extrascat getextrascat() { return extrascat; } public void setextrascat(extrascat extrascat) { this.extrascat = extrascat; } }
extras.java
@entity @table(name = "extras") public class extras implements serializable { private static final long serialversionuid = 8644201177004602944l; @id private int idextras; private string name; private double priceincents; @manytoone(fetch = fetchtype.eager, cascade = cascadetype.all) @joincolumn(name = "idextrascat") private extrascat extrascat; @manytomany(cascade = { cascadetype.all }, mappedby = "extras") private set<orderitem> orderitem = new hashset<orderitem>(); // constructors public extras() { } public extras(int idextras, string name, double priceincents, extrascat extrascat) { this.idextras = idextras; this.name = name; this.priceincents = priceincents; this.extrascat = extrascat; } // getters , setters public int getidextras() { return idextras; } public void setidextras(int idextras) { this.idextras = idextras; } public string getname() { return name; } public void setname(string name) { this.name = name; } public double getpriceincents() { return priceincents; } public void setpriceincents(double priceincents) { this.priceincents = priceincents; } public extrascat getextrascat() { return extrascat; } public void setextrascat(extrascat extrascat) { this.extrascat = extrascat; } }
zaki correct suggest creating new bean ui. querying 1 table , expecting results multiple tables. instead, populate new object holds values need , use object in view.
wiki
Comments
Post a Comment