Error looping through a Set
ruthlesset Jun 21, 2011 7:43 PMI am just on my first month still trying to learn SEAM and am having a hard time figuring out this error. I have two tables with the primary key of the table M_Module mapped to the foreign key module_recid of the table M_Function. When I try to loop through the functions of a module I get an error. What am I doing wrong?
MModule.java
package com.demo.model;
// Generated Mar 9, 2011 10:27:42 AM by Hibernate Tools 3.2.4.GA
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@Entity
@Table(name = "M_MODULE")
@SequenceGenerator(name = "moduleSeq", sequenceName = "M_MODULE_SEQ")
public class MModule implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer recid;
private String name;
private Set<MFunction> MFunctions = new HashSet<MFunction>(0);
public MModule() {
}
public MModule(Integer recid, String name) {
this.recid = recid;
this.name = name;
}
public MModule(Integer recid, String name,
Set<MFunction> MFunctions) {
this.recid = recid;
this.name = name;
this.MFunctions = MFunctions;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "moduleSeq")
@Column(name = "RECID", unique = true, nullable = false, precision = 5, scale = 0)
public Integer getRecid() {
return this.recid;
}
public void setRecid(Integer recid) {
this.recid = recid;
}
@Column(name = "NAME", nullable = false, length = 80)
@NotNull
@Length(max = 80)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(fetch=FetchType.LAZY, mappedBy="MModule")
public Set<MFunction> getMFunctions() {
return this.MFunctions;
}
public void setMFunctions(Set<MFunction> MFunctions) {
this.MFunctions = MFunctions;
}
}
--------------------------------------------------------------------------------------------------------------
MModuleHome.java
package com.demo.action;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;
import com.demo.model.MFunction;
import com.demo.model.MModule;
@Name("mModuleHome")
public class MModuleHome extends EntityHome<MModule> {
private static final long serialVersionUID = 1L;
@In private EntityManager entityManager;
public void setmModuleRecid(Integer id) {
setId(id);
}
public Integer getmModuleRecid() {
return (Integer) getId();
}
@Override
protected MModule createInstance() {
MModule mModule = new MModule();
return mModule;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
}
public boolean isWired() {
return true;
}
public MModule getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
public List<MFunction> getMFunctions() {
return getInstance() == null ? null : new ArrayList<MFunction>(
getInstance().getMFunctions());
}
}
--------------------------------------------------------------------------------------------------------------
MFunction.java
package com.demo.model;
// Generated Mar 9, 2011 10:27:42 AM by Hibernate Tools 3.2.4.GA
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
/**
* MModule generated by hbm2java
*/
@Entity
@Table(name = "M_FUNCTION")
@SequenceGenerator(name = "functionSeq", sequenceName = "M_FUNCTION_SEQ")
public class MFunction implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer recid;
private MModule MModule;
private String name;
private Set<MContext> MContexts = new HashSet<MContext>(0);
public MFunction() {
}
public MFunction(Integer recid, MModule MModule, String name) {
this.recid = recid;
this.MModule = MModule;
this.name = name;
}
public MFunction(Integer recid, MModule MModule, String name,
Set<MContext> MContexts) {
this.recid = recid;
this.MModule = MModule;
this.name = name;
this.MContexts = MContexts;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "functionSeq")
@Column(name = "RECID", unique = true, nullable = false, precision = 5, scale = 0)
public Integer getRecid() {
return this.recid;
}
public void setRecid(Integer recid) {
this.recid = recid;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="MODULE_RECID", nullable=false)
@NotNull
public MModule getMModule() {
return this.MModule;
}
public void setMModule(MModule MModule) {
this.MModule = MModule;
}
@Column(name = "NAME", nullable = false, length = 50)
@NotNull
@Length(max = 50)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "MFunction")
public Set<MContext> getMContexts() {
return this.MContexts;
}
public void setMContexts(Set<MContext> MContexts) {
this.MContexts = MContexts;
}
}
--------------------------------------------------------------------------------------------------------------
MFunctionHome.java
package com.demo.action;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.log.Log;
import com.demo.model.MContext;
import com.demo.model.MFunction;
import com.demo.model.MModule;
@Name("mFunctionHome")
public class MFunctionHome extends EntityHome<MFunction> {
private static final long serialVersionUID = 1L;
@In(create = true)
MModuleHome mModuleHome;
@Logger private Log log;
public void setmFunctionRecid(Integer id) {
setId(id);
}
public Integer getmFunctionRecid() {
return (Integer) getId();
}
@Override
protected MFunction createInstance() {
MFunction mFunction = new MFunction();
return mFunction;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
MModule MModule = mModuleHome.getDefinedInstance();
if (MModule != null) {
getInstance().setMModule(MModule);
}
}
public boolean isWired() {
if (getInstance().getMModule() == null)
return false;
return true;
}
public MFunction getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
public List<MContext> getMContexts() {
return getInstance() == null ? null : new ArrayList<MContext>(
getInstance().getMContexts());
}
}
--------------------------------------------------------------------------------------------------------------
modules.xhtml
<ui:repeat value="#{moduleList}" var="module">
<h:outputText value="[#{module.name}]" />
<ui:repeat value="#{module.MFunctions}" var="function">
<h:outputText value=" -- #{function.name} -- " />
</ui:repeat>
<h:outputText value="," />
</ui:repeat>
I get the error
/modules.xhtml @75,53 value=" -- #{function.name} -- ": The class 'org.hibernate.collection.PersistentSet' does not have the property 'name'.
MModule.java
package com.demo.model;
// Generated Mar 9, 2011 10:27:42 AM by Hibernate Tools 3.2.4.GA
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@Entity
@Table(name = "M_MODULE")
@SequenceGenerator(name = "moduleSeq", sequenceName = "M_MODULE_SEQ")
public class MModule implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer recid;
private String name;
private Set<MFunction> MFunctions = new HashSet<MFunction>(0);
public MModule() {
}
public MModule(Integer recid, String name) {
this.recid = recid;
this.name = name;
}
public MModule(Integer recid, String name,
Set<MFunction> MFunctions) {
this.recid = recid;
this.name = name;
this.MFunctions = MFunctions;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "moduleSeq")
@Column(name = "RECID", unique = true, nullable = false, precision = 5, scale = 0)
public Integer getRecid() {
return this.recid;
}
public void setRecid(Integer recid) {
this.recid = recid;
}
@Column(name = "NAME", nullable = false, length = 80)
@NotNull
@Length(max = 80)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(fetch=FetchType.LAZY, mappedBy="MModule")
public Set<MFunction> getMFunctions() {
return this.MFunctions;
}
public void setMFunctions(Set<MFunction> MFunctions) {
this.MFunctions = MFunctions;
}
}
--------------------------------------------------------------------------------------------------------------
MModuleHome.java
package com.demo.action;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;
import com.demo.model.MFunction;
import com.demo.model.MModule;
@Name("mModuleHome")
public class MModuleHome extends EntityHome<MModule> {
private static final long serialVersionUID = 1L;
@In private EntityManager entityManager;
public void setmModuleRecid(Integer id) {
setId(id);
}
public Integer getmModuleRecid() {
return (Integer) getId();
}
@Override
protected MModule createInstance() {
MModule mModule = new MModule();
return mModule;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
}
public boolean isWired() {
return true;
}
public MModule getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
public List<MFunction> getMFunctions() {
return getInstance() == null ? null : new ArrayList<MFunction>(
getInstance().getMFunctions());
}
}
--------------------------------------------------------------------------------------------------------------
MFunction.java
package com.demo.model;
// Generated Mar 9, 2011 10:27:42 AM by Hibernate Tools 3.2.4.GA
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
/**
* MModule generated by hbm2java
*/
@Entity
@Table(name = "M_FUNCTION")
@SequenceGenerator(name = "functionSeq", sequenceName = "M_FUNCTION_SEQ")
public class MFunction implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer recid;
private MModule MModule;
private String name;
private Set<MContext> MContexts = new HashSet<MContext>(0);
public MFunction() {
}
public MFunction(Integer recid, MModule MModule, String name) {
this.recid = recid;
this.MModule = MModule;
this.name = name;
}
public MFunction(Integer recid, MModule MModule, String name,
Set<MContext> MContexts) {
this.recid = recid;
this.MModule = MModule;
this.name = name;
this.MContexts = MContexts;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "functionSeq")
@Column(name = "RECID", unique = true, nullable = false, precision = 5, scale = 0)
public Integer getRecid() {
return this.recid;
}
public void setRecid(Integer recid) {
this.recid = recid;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="MODULE_RECID", nullable=false)
@NotNull
public MModule getMModule() {
return this.MModule;
}
public void setMModule(MModule MModule) {
this.MModule = MModule;
}
@Column(name = "NAME", nullable = false, length = 50)
@NotNull
@Length(max = 50)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "MFunction")
public Set<MContext> getMContexts() {
return this.MContexts;
}
public void setMContexts(Set<MContext> MContexts) {
this.MContexts = MContexts;
}
}
--------------------------------------------------------------------------------------------------------------
MFunctionHome.java
package com.demo.action;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.log.Log;
import com.demo.model.MContext;
import com.demo.model.MFunction;
import com.demo.model.MModule;
@Name("mFunctionHome")
public class MFunctionHome extends EntityHome<MFunction> {
private static final long serialVersionUID = 1L;
@In(create = true)
MModuleHome mModuleHome;
@Logger private Log log;
public void setmFunctionRecid(Integer id) {
setId(id);
}
public Integer getmFunctionRecid() {
return (Integer) getId();
}
@Override
protected MFunction createInstance() {
MFunction mFunction = new MFunction();
return mFunction;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
MModule MModule = mModuleHome.getDefinedInstance();
if (MModule != null) {
getInstance().setMModule(MModule);
}
}
public boolean isWired() {
if (getInstance().getMModule() == null)
return false;
return true;
}
public MFunction getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
public List<MContext> getMContexts() {
return getInstance() == null ? null : new ArrayList<MContext>(
getInstance().getMContexts());
}
}
--------------------------------------------------------------------------------------------------------------
modules.xhtml
<ui:repeat value="#{moduleList}" var="module">
<h:outputText value="[#{module.name}]" />
<ui:repeat value="#{module.MFunctions}" var="function">
<h:outputText value=" -- #{function.name} -- " />
</ui:repeat>
<h:outputText value="," />
</ui:repeat>
I get the error
/modules.xhtml @75,53 value=" -- #{function.name} -- ": The class 'org.hibernate.collection.PersistentSet' does not have the property 'name'.