Hibernate Mapping - Converting XML to Annotation - Wrong Column name being generated - spring

I have a two projects in hibernate one is for XML and one is for annotation.
My XML Mapping config works fine with composite keys while the annotation style generates a wrong column.
Annotation Style Generates this table
Hibernate: create table agent (agent_id number(10,0) not null, start_dttm timestamp not null, agent_cd varchar2(255 char), end_dttm timestamp, primary key (agent_id, start_dttm))
Hibernate: create table agent_license (agent_license_id number(10,0) not null, agent_agent_id number(10,0), agent_start_dttm timestamp, agent_id number(10,0), primary key (agent_license_id))
Hibernate: alter table agent_license add constraint FKncan0jjmt1siq0a6a19ll978m foreign key (agent_agent_id, agent_start_dttm) references agent
Hibernate: alter table agent_license add constraint FKp64d6078jnxi3hq0n0es0yhs foreign key (agent_id, agent_start_dttm) references agent
a redundant column for AgentLicense with agent_agent_id instead of agent_id only.
This is Working Correctly XML Config
XML generates
Agent Table with column agent_id,start_dttm,agent_cd
Agent_License with column agent_id,agent_start_dttm
Agent Model
<class name="com.poc.model.Agent" table="AGENT">
<composite-id name="id" class="com.poc.model.pk.AgentPK">
<key-property name="agentId" type="long">
<column name="AGENT_ID" precision="10" scale="0" />
</key-property>
<key-property name="startDateTime" type="timestamp">
<column name="START_DTTM" />
</key-property>
</composite-id>
<property name="agentCode" type="string">
<column name="AGENT_CD" length="20" />
</property>
<set name="agentLicenses" table="AGENT_LICENSE" inverse="true" lazy="true" fetch="select">
<key>
<column name="AGENT_ID" precision="10" scale="0" />
<column name="AGENT_START_DTTM" />
</key>
<one-to-many class="com.poc.model.AgentLicense" />
</set>
</class>
AgentLicense Model
<class name="com.poc.model.AgentLicense" table="AGENT_LICENSE">
<id name="agentLicenseId" type="long">
<column name="AGENT_LICENSE_ID" precision="10" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="agent" class="com.poc.model.Agent" fetch="select">
<column name="AGENT_ID" precision="10" scale="0" />
<column name="AGENT_START_DTTM" />
</many-to-one>
<property name="licenseNum" type="string">
<column name="LICENSE_NUM" length="40" />
</property>
</class>
Agent PK Model
<class name="com.poc.model.Agent" table="AGENT">
<composite-id name="id" class="com.poc.model.pk.AgentPK">
<key-property name="agentId" type="long">
<column name="AGENT_ID" precision="10" scale="0" />
</key-property>
<key-property name="startDateTime" type="timestamp">
<column name="START_DTTM" />
</key-property>
</composite-id>
<property name="agentCode" type="string">
<column name="AGENT_CD" length="20" />
</property>
<set name="agentLicenses" table="AGENT_LICENSE" inverse="true" lazy="true" fetch="select">
<key>
<column name="AGENT_ID" precision="10" scale="0" />
<column name="AGENT_START_DTTM" />
</key>
<one-to-many class="com.poc.model.AgentLicense" />
</set>
</class>
Correct Annotation is this
Result table generation
Agent Table with column agent_id,start_dttm,agent_cd
Agent_License with column agent_id,agent_start_dttm
public class Agent {
#EmbeddedId
#AttributeOverrides({
#AttributeOverride(name = "agentId", column = #Column(name = "AGENT_ID", nullable = false)),
#AttributeOverride(name = "startDateTime", column = #Column(name = "START_DTTM", nullable = false)) })
private AgentPK agentPK;
#Column(name="AGENT_CODE")
private String agentCode;
#OneToMany(fetch = FetchType.LAZY, mappedBy = "agent")
private Set<AgentLicense> agentLicenses = new HashSet<AgentLicense>();
}
public class AgentLicense {
#Id
#Column(name = "AGENT_LICENSE_ID", unique = true, nullable = false)
private long agentLicenseId;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumns({ #JoinColumn(name = "AGENT_ID", referencedColumnName = "AGENT_ID"),
#JoinColumn(name = "AGENT_START_DTTM", referencedColumnName = "START_DTTM") })
private Agent agent;
}
#Embeddable
public class AgentPK implements Serializable{
#Column(name = "AGENT_ID", nullable = false, precision = 10, scale = 0)
private long agentId;
#Column(name = "START_DTTM", nullable = false)
#Temporal(TemporalType.TIMESTAMP)
private Date startDateTime;
//HashCode and equals here
}
Correct Full answer

Fix your inverse mapping for AgentLicense in Agent
public class Agent {
// ...
#OneToMany(mappedBy = "agent")
#JoinColumns( ... )
private Set<AgentLicense> agentLicenses;
}

Related

Hibernate Envers Audit Join Table defenition

I want to add history to my entities and I am playing arround with hibernate Envers.
I have defined Handbook and Chapter classes with the coresponding 5 tables:
HANDBOOK, HANDBOOK_AUD, CHAPTER, CHAPTER_AUD and REVINFO.
If there is no connection between the 2 entities, everithing works fine, but when I add oneToMany relationship for HANDBOOK and CHPATER the application fails to start because of missing HANDBOOK_CHAPTER_AUD table.
Thinking about it is absolutely fine to have that JoinTable, but the problem is how should define it.
Handbook entity:
#Entity
#Audited
#Getter
#Setter
#NoArgsConstructor
public class Handbook {
#Id
#SequenceGenerator(name = "HANDBOOK_ID_SEQUENCE", sequenceName = "HANDBOOK_ID_SEQUENCE", allocationSize = 1)
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HANDBOOK_ID_SEQUENCE")
private Long id;
private String title;
#OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
#JoinColumn(name = "HANDBOOK_ID")
#AuditJoinTable(name = "REV_HANDBOOK_CHAPTER")
private Set<Chapter> chapters;
}
Chapter entity:
#Entity
#Audited
#Getter
#Setter
#NoArgsConstructor
public class Chapter {
#Id
#SequenceGenerator(name = "CHAPTER_ID_SEQUENCE", sequenceName = "CHAPTER_ID_SEQUENCE", allocationSize = 1)
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CHAPTER_ID_SEQUENCE")
private Long id;
private String name;
#Column(name = "HANDBOOK_ID")
private Long handbookId;
}
Tables deffinition:
<createTable tableName="REVINFO">
<column name="rev" type="integer">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="revtstmp" type="bigint"/>
</createTable>
<!-- Hibernate Envers need this seq exact to increase the revision number for versioned entities-->
<createSequence sequenceName="HIBERNATE_SEQUENCE"
startValue="1"
incrementBy="1"/>
<createTable tableName="HANDBOOK">
<column name="ID" type="bigint">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="TITLE" type="varchar2(128 char)"/>
</createTable>
<createTable tableName="REV_HANDBOOK">
<column name="ID" type="bigint"/>
<column name="TITLE" type="varchar2(128 char)"/>
<column name="REV_ID" type="integer">
<constraints foreignKeyName="FK_HANDBOOK_REV"
references="REVINFO(REV)"/>
</column>
<column name="REV_TYPE" type="smallint"/>
</createTable>
<!-- CHAPTER TABLES -->
<createTable tableName="CHAPTER">
<column name="ID" type="bigint">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="NAME" type="varchar2(128 char)"/>
<column name="HANDBOOK_ID" type="integer">
<constraints foreignKeyName="FK_CHAPTER_HANDBOOK_ID"
references="HANDBOOK(ID)"/>
</column>
</createTable>
<createTable tableName="REV_CHAPTER">
<column name="ID" type="bigint"/>
<column name="NAME" type="varchar2(128 char)"/>
<column name="HANDBOOK_ID" type="integer">
<constraints foreignKeyName="FK_CHAPTER_AUD_HANDBOOK_ID"
references="HANDBOOK(ID)"/>
</column>
<column name="REV_ID" type="integer">
<constraints foreignKeyName="FK_CHAPTER_REV"
references="REVINFO(REV)"/>
</column>
<column name="REV_TYPE" type="smallint"/>
</createTable>
NOTE:
I have edited some namings according to the hibernate envers documentation:
org:
hibernate:
envers:
audit_table_prefix: REV_
audit_table_suffix: ~ # No suffix
revision_field_name: REV_ID
revision_type_field_name: REV_TYPE
I have found out a sollution based on the series of errors hibernate gave me after running the code. Here is how I defiend the revision join table:
<createTable tableName="REV_HANDBOOK_CHAPTER">
<column name="ID" type="bigint"/>
<column name="REV_ID" type="integer">
<constraints foreignKeyName="FK_REV_HANDBOOK_CHAPTER_REV"
references="REVINFO(REV)"/>
</column>
<column name="HANDBOOK_ID" type="bigint">
<constraints foreignKeyName="FK_REV_HANDBOOK_CHAPTER_HANDBOOK"
references="HANDBOOK(ID)"/>
</column>
<column name="REV_TYPE" type="smallint"/>
</createTable>

Unkown column in 'field list' after creating tables by liquibase

I prepare liquibase scripts to generate my tables and relationships.
ChangeLog which create relationships:
<changeSet id="1" author="xyz">
<createTable tableName="drivers_and_tickets">
<column name="driver_id" type="varchar(36)">
<constraints nullable="false" />
</column>
<column name="ticket_id" type="varchar(36)">
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint constraintName="fk_drivers"
baseTableName="drivers_and_tickets" baseColumnNames="driver_id"
referencedTableName="drivers" referencedColumnNames="id" />
<addForeignKeyConstraint constraintName="fk_tickets"
baseTableName="drivers_and_tickets" baseColumnNames="ticket_id"
referencedTableName="tickets" referencedColumnNames="id" />
</changeSet>
<changeSet id="2" author="xyz">
<createTable tableName="tickets_and_offences">
<column name="ticket_id" type="varchar(36)">
<constraints nullable="false" />
</column>
<column name="offence_id" type="varchar(36)">
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint constraintName="fk_tickets_from_offences"
baseTableName="tickets_and_offences" baseColumnNames="ticket_id"
referencedTableName="tickets" referencedColumnNames="id" />
<addForeignKeyConstraint constraintName="fk_offences"
baseTableName="tickets_and_offences" baseColumnNames="offence_id"
referencedTableName="offences" referencedColumnNames="id" />
</changeSet>
And it ok, app is starting without any errors.
I use hibernate too, so I prepared entites:
public class DriverEntity {
#Id
#GeneratedValue(generator = "system-uuid")
#GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
private String name;
private String surname;
private String email;
#OneToMany(mappedBy="driver")
private List<TicketEntity> tickets;
public class TicketEntity {
#Id
#GeneratedValue(generator = "system-uuid")
#GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
private LocalDate date;
#OneToMany(mappedBy="ticket")
private Set<OffenceEntity> offences;
#ManyToOne
#JoinColumn(name="driver_id")
private DriverEntity driver;
and next when I call repository findAllDrivers I am getting error:
"Unknown column 'tickets0_.driver_id' in 'field list'" .
When I was using hibernate.ddl-auto mapping like that in entities was enough to create tables and getting records from database.
Edit:
I have checked how it looks in my DB and do not know what is wrong

Liquibase , how to add a group of fields like primary key?

I have an entity with a group of fields in primary key.
Like this :
#Entity
#Table(name = "pv_object")
#NamedQuery(name = "PreviousObject.findAll", query = "SELECT p FROM PreviousObject p")
public class PreviousObject implements Serializable {
#EmbeddedId
private FieldsDTO fieldsdto;
//
}
FieldsDTO class contains 2 String and 2 Integer.
I have and I use Liquidbase on my project in a XML file, but, I don't know how to represent this ID of 4 fields in liquidbase.
Thanks for your help :)
In <addPrimaryKey you can configure columnNames by all your columns that compose your primary key
<changeSet author="liquibase-docs" id="addPrimaryKey-example">
<addPrimaryKey
columnNames="id, name"
constraintName="pk_person"
schemaName="public"
tableName="person"
tablespace="A String"/>
</changeSet>
Assign the same primaryKeyName to them.
<createTable tableName="pv_object">
<column name="x" type="bigint">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_pv_object"/>
</column>
<column name="y" type="bigint">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_pv_object"/>
</column>
</createTable>
or add separately
<addPrimaryKey tableName="REPRESENTATIVE" columnNames="REPRESENTED_USER_ID,REPRESENTATIVE_ID"
constraintName="REPRESENTED_REPRESENTATIVE_PK" />

Mapping a composite primary key with a foreign key relation in Nhibernate

a company I am working for is using an ERP and it's legacy database is Oracle.
Until now I've used packages (oracle stored procedures) to access data but during the years the number has grown consistently and now I can't manage them anymore.
I was trying to do some experiments with Nhibernate and started mapping few tables.
All the tables have composite primary keys.
A brief description:
Table Order (table name: OCSAORH)
OCHORDN (PK) => OrderNumber
OCHAMND (PK)
OCHCOSC (PK) => Company
OCHCLII
...
Table OrderLine (table name: OCSALIN)
OCLORDN (PK) => OrderNumber
OCLAMND (PK)
OCLCOSC (PK) => Company
OCLLINN (PK) => Line Number
OCLSSEQ (PK)
OCLITMN
...
This is my mapping
Order:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MvcOracleNhibernate"
namespace="MvcOracleNhibernate.Domain">
<class name="Order" table="OCSAORH">
<composite-id>
<key-property name="Number" column="OCHORDN"></key-property>
<key-property name="Ver" column="OCHAMND"></key-property>
<key-property name="Company" column="OCHCOSC"></key-property>
</composite-id>
<property name="CustomerCode" column="OCHCLII" type="String" length="10"></property>
<property name="Reference" column="OCHOCNO" type="String" length="25"></property>
<property name="Date" column="OCHOCDT" type="Double"></property>
<bag name="OrderLines" cascade="all-delete-orphan" generic="true" inverse="true" lazy="false">
<key>
<column name="OCLORDN" not-null="true"/>
<column name="OCLAMND" not-null="true"/>
<column name="OCLCOSC" not-null="true"/>
</key>
<one-to-many class="OrderLine" not-found="ignore"/>
</bag>
</class>
</hibernate-mapping>
OrderLine:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MvcOracleNhibernate"
namespace="MvcOracleNhibernate.Domain">
<class name="OrderLine" table="OCSALIN">
<composite-id>
<key-property name="Number" column="OCLORDN"></key-property>
<key-property name="Ver" column="OCLAMND" ></key-property>
<key-property name="Company" column="OCLCOSC"></key-property>
<key-property name="Line" column="OCLLINN"></key-property>
<key-property name="Seq" column="OCLSSEQ"></key-property>
</composite-id>
<property name="Item" column="OCLITMN" type="String" length="19"></property>
<property name="Quantity" column="OCLQTYP" type="Double"></property>
</class>
</hibernate-mapping>
With these mappings everything works fine; I can load an order and the lazy loading loads my lines.
While reading some documentation I've noticed that I haven't defined the many-to-one relation so I've added this:
<many-to-one name="Order" class="Order" lazy="proxy">
<column name="OCHORDN" not-null="true"/>
<column name="OCHAMND" not-null="true"/>
<column name="OCHCOSC" not-null="true"/>
</many-to-one>
to the OrderLine mapping file.
Now if I run my test app the order is loaded properly but the order lines are not loaded.
I get a {NHibernate.ADOException} = {"could not initialize a collection: ... }
I've tried to investigate and noticed that the generated query to retrieve the rows is wrong. This is the SQL:
SELECT
orderlines0_.OCLORDN as OCLORDN1_,
orderlines0_.OCLAMND as OCLAMND1_,
orderlines0_.OCLCOSC as OCLCOSC1_,
orderlines0_.OCLLINN as OCLLINN1_,
orderlines0_.OCLSSEQ as OCLSSEQ1_,
orderlines0_.OCLORDN as OCLORDN13_0_,
orderlines0_.OCLAMND as OCLAMND13_0_,
orderlines0_.OCLCOSC as OCLCOSC13_0_,
orderlines0_.OCLLINN as OCLLINN13_0_,
orderlines0_.OCLSSEQ as OCLSSEQ13_0_,
orderlines0_.OCLITMN as OCLITMN13_0_,
orderlines0_.OCLQTYP as OCLQTYP13_0_,
orderlines0_.OCHORDN as OCHORDN13_0_,
orderlines0_.OCHAMND as OCHAMND13_0_,
orderlines0_.OCHCOSC as OCHCOSC13_0_
FROM OCSALIN orderlines0_
WHERE
orderlines0_.OCLORDN=?
and orderlines0_.OCLAMND=?
and orderlines0_.OCLCOSC=?
As you can notice the last 3 fields of the select (those with the prefix OCH instead of OCL) aren't members of the OCSALIN table; they are the key of the OCSAORH.
After 1 days spent reading documentation and examples I can't figure out what I am doing wrong.
Is there anybody there who can try to help?
This is the expected behavior. You're defining the foreign keys in your many-to-one mapping. So the columns need to exist in the object you're defining.
I think you want this
<many-to-one name="Order" class="Order" lazy="proxy">
<column name="OCLORDN" not-null="true"/>
<column name="OCLAMND" not-null="true"/>
<column name="OCLCOSC" not-null="true"/>
</many-to-one>

Error 500: could not initialize a collection in hibernate mapping

I am a newbie for Hibernate. Hope you guys can help me debug below error which really make me crazy.
I got a table called CONTENT_WORKGROUP which will map to another table called CONTENT_WORKGROUP_ROLE. Below is the table structure and sample data:
CONTENT_WORKGROUP
CM_WORKGROUP_ID NUMBER(15,0)
WORKGROUP_ID NUMBER(15,0)
ROLE_ID VARCHAR2(20 BYTE)
CONTENT_WORKGROUP_ROLE
CM_WORKGROUP_ROLE_ID NUMBER(15,0)
ROLE_ID VARCHAR2(20 BYTE)
FUNCTION_ID VARCHAR2(40 BYTE)
P/S: One user workgroup can have multiple role (Creator, Admin, Approver). The function(Add, Edit, Delete) that can perform by this workgroup can be query from CONTENT_WORKGROUP_ROLE.
Sample DATA:
CONTENT_WORKGROUP
CM_WORKGROUP_ID WORKGROUP_ID ROLE_ID
1 136 Creator
2 137 Administrator
3 136 Administrator
CONTENT_WORKGROUP_ROLE
CM_WORKGROUP_ROLE_ID ROLE_ID FUNCTION_ID
1 Creator Copy
2 Creator Edit
3 Creator Delete
4 Creator Add
5 Administrator Edit
6 Administrator Approve
7 Administrator Reject
However, I am getting the error when I get the SET of ContentWorkgroupRole hold by particular workgroup.
[11/23/10 15:28:56:053 SGT] 00000039 SystemOut O [23/11/2010 15:28:56.053] ERROR JDBCExceptionReporter - ORA-01722: invalid number
[11/23/10 15:28:56:100 SGT] 00000039 ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: action. Exception thrown : javax.servlet.ServletException: could not initialize a collection: [corp.celcom.next.infochannel.model.ContentWorkgroup.contentWorkgroupRole#1]
Below is my hibernate mapping file:
ContentWorkgroup.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroup" table="CM_WORKGROUP" >
<id name="cmWorkgroupId" type="long">
<column name="CM_WORKGROUP_ID" precision="15" scale="0" />
CM_WORKGROUP
CM_WORKGROUP_ID
ContentWorkgroupRole.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroupRole" table="CM_WORKGROUP_ROLE" >
<id name="cmWorkgroupRoleId" type="long">
CM_WORKGROUP_ROLE_ID
CM_WORKGROUP_ROLE
<many-to-one name="contentWorkgroup" class="corp.celcom.next.infochannel.model.ContentWorkgroup" fetch="select">
<column name="ROLE_ID" precision="15" scale="0" />
</many-to-one>
In my ACTION class, the above mentioned error occured on this line:
Iterator iter = cw.getContentWorkgroupRole().iterator();
for(ContentWorkgroup cw : contentWorkgroupList)
{
Iterator iter = cw.getContentWorkgroupRole().iterator();
while (iter.hasNext()) {
ContentWorkgroupRole role = (ContentWorkgroupRole) iter.next();
if (role.getFunctionId().equalsIgnoreCase(Constant.ADD))
myForm.setAllowAdd(true);
if (role.getFunctionId().equalsIgnoreCase(Constant.EDIT))
myForm.setAllowEdit(true);
if (role.getFunctionId().equalsIgnoreCase(Constant.DELETE))
myForm.setAllowDelete(true);
}
}
The weird part is when I change the ROLE_ID to Integer/Long (i.e 1-Creator, 2-Administrator), instead of using String, it work fine! I couldn't understand why and what the problem on my code.
Thanks for you help. It took me 1 day already to cope with this error. Thanks!
Sorry, the display seem got abit problem. I write again here:
ContentWorkgroup.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroup" table="CM_WORKGROUP" >
<id name="cmWorkgroupId" type="long">
<column name="CM_WORKGROUP_ID" precision="15" scale="0" />
<generator class="corp.celcom.next.util.MultipleTableGenerator" >
<param name="KEYTABLE_VALUE">CM_WORKGROUP</param>
<param name="KEYCOLUMN_VALUE">CM_WORKGROUP_ID</param>
</generator>
</id>
<property name="workgroupId" type="long">
<column name="WORKGROUP_ID" precision="15" scale="0" not-null="true" />
</property>
<property name="srId" type="string">
<column name="SR_ID" length="15" not-null="true" />
</property>
<property name="contentCategoryId" type="string">
<column name="CONTENT_CATEGORY_ID" length="40" not-null="true" />
</property>
<property name="roleId" type="string">
<column name="ROLE_ID" length="20" not-null="true" />
</property>
<set name="contentWorkgroupRole" table="CM_WORKGROUP_ROLE" inverse="true">
<key>
<column name="ROLE_ID" length="20" not-null="true" />
</key>
<one-to-many class="corp.celcom.next.infochannel.model.ContentWorkgroupRole" />
</set>
</class>
ContentWorkgroupRole.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroupRole" table="CM_WORKGROUP_ROLE" >
<id name="cmWorkgroupRoleId" type="long">
<column name="CM_WORKGROUP_ROLE_ID" precision="15" scale="0" />
<generator class="corp.celcom.next.util.MultipleTableGenerator">
<param name="KEYCOLUMN_VALUE">CM_WORKGROUP_ROLE_ID</param>
<param name="KEYTABLE_VALUE">CM_WORKGROUP_ROLE</param>
</generator>
</id>
<many-to-one name="contentWorkgroup" class="corp.celcom.next.infochannel.model.ContentWorkgroup" fetch="select">
<column name="ROLE_ID" precision="15" scale="0" />
</many-to-one>
<property name="menuId" type="string">
<column name="MENU_ID" length="40" not-null="true" />
</property>
<property name="functionId" type="string">
<column name="FUNCTION_ID" length="40" not-null="true" />
</property>
In my ACTION class, the above mentioned error occured on this line:
Iterator iter = cw.getContentWorkgroupRole().iterator();
for(ContentWorkgroup cw : contentWorkgroupList)
{
Iterator iter = cw.getContentWorkgroupRole().iterator();
while (iter.hasNext()) {
ContentWorkgroupRole role = (ContentWorkgroupRole) iter.next();
if (role.getFunctionId().equalsIgnoreCase(Constant.ADD))
myForm.setAllowAdd(true);
if (role.getFunctionId().equalsIgnoreCase(Constant.EDIT))
myForm.setAllowEdit(true);
if (role.getFunctionId().equalsIgnoreCase(Constant.DELETE))
myForm.setAllowDelete(true);
}
}

Resources