[jboss-user] [EJB 3.0] - is this a bug in EJB?
mnrz
do-not-reply at jboss.com
Sat Sep 22 06:45:55 EDT 2007
hello
I have some entity in my application, when I declare a method starting with term "is" the database will be updated with a new field whereas I didn't declare that field as a database field
here is an example:
| import static org.jboss.seam.ScopeType.SESSION;
|
| import java.io.Serializable;
| import java.util.HashSet;
| import java.util.Set;
|
| import javax.persistence.CascadeType;
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.FetchType;
| import javax.persistence.GeneratedValue;
| import javax.persistence.Id;
| import javax.persistence.OneToMany;
| import javax.persistence.Table;
|
| import org.hibernate.validator.NotNull;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
|
| @Entity
| @Table(name ="group_permission")
| @Name("group")
| @Scope(SESSION)
| public class Group implements Serializable{
|
| private String name;
| private Long id;
| private Integer permissionGroup = new Integer(0);
| private Set<Permission> permissions =new HashSet<Permission>();
| private static final int Export_Permission = 8;
| private static final String All_Permission = "*";
|
| @OneToMany(mappedBy="group", fetch = FetchType.EAGER ,cascade=CascadeType.ALL )
| public Set<Permission> getPermissions() {
| return permissions;
| }
|
| public void setPermissions(Set<Permission> permissions) {
| this.permissions = permissions;
| }
| @Id @GeneratedValue
| @Column(name = "id")
| public Long getId() {
| return id;
| }
| public void setId(Long id) {
| this.id = id;
| }
|
| @NotNull
| @Column(name="name")
| public String getName() {
| return name;
| }
| public void setName(String name) {
| this.name = name;
| }
| public boolean equals(Object o) {
| if (o == null)
| return false;
|
| if (!(o instanceof Group))
| return false;
|
| Group that = (Group) o;
|
| return this.getName().equals(that.getName());
| }
|
| public int hashCode() {
|
| return this.getName().hashCode()+720;
|
| }
|
| @Column(name="permissionGroup")
| public Integer getPermissionGroup() {
| return permissionGroup;
| }
|
| public void setPermissionGroup(Integer permissionGroup) {
| this.permissionGroup = permissionGroup;
| }
| public void setPermission(boolean permission){
| permissionGroup=0;
| if(permission){
| permissionGroup=permissionGroup | Export_Permission;
| }
|
| }
| public void addPermission(ColumnHeader ch ,String categoryName){
|
| if(permissions==null){
| permissions=new HashSet<Permission>();
| }
| if(ch.isDisplayable() ||ch.isSearchable()){
| Permission permission=new Permission();
| permission.setGroup(this);
| permission.setCategory(categoryName);
| permission.displayablePermission(ch.isDisplayable());
| permission.searchablePermission(ch.isSearchable());
| permission.setFieldName(ch.getName());
| permissions.add(permission);
| }
| }
|
| public boolean hasExportPermission(){
| if((Export_Permission & Export_Permission) == Export_Permission)
| return true;
| else
| return false;
| }
|
| public void setExportPermission(boolean export){
| if(export) {
| permissionGroup = permissionGroup | Export_Permission;
| }else {
| permissionGroup = permissionGroup & ~Export_Permission;
| }
| }
|
| public boolean hasDisplayPermission(String categoryName, String fieldName) {
| for(Permission p: permissions) {
| if(p.getCategory().trim().equals(All_Permission)){
| return true;
| }
| if(p.getCategory().equals(categoryName) && p.getFieldName().equals(fieldName)) {
| return p.hasDisplayablePermission();
| }
| }
| return false;
| }
|
| public boolean hasSearchPermission(String categoryName, String fieldName) {
| for(Permission p: permissions) {
| if(p.getCategory().equals(All_Permission)){
| return true;
| }
| if(p.getCategory().equals(categoryName) && p.getFieldName().equals(fieldName)) {
| return p.hasSearchablePermission();
| }
| }
| return false;
| }
|
| }
|
|
as you can see in above code represented in blue color, I have some utility method in my entity, if I rename the method hasExportPermission() to isExportPermission() the EJB will create a field in corresponding table with name exportPermission and because it returns boolean the type of the field will be tinyint(1) (using mySql)
I expect since I didn't declare it by annotations it shouldn't consider it as a table field, but it does!!!!
I want to know whether this is a bug or I made a mistake somewhere
it is remarkable to say that I am using JBoss Seam framework, but I don't think this is its fault.
thank you very much
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4087492#4087492
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4087492
More information about the jboss-user
mailing list