使用带有Spring Security插件的Java域对象

时间:2009-07-29 22:01:18

标签: java grails spring-security

我正在使用遗留数据库和相应的Java Domain Classes。我正在尝试将Spring Security添加到应用程序中,我也想使用Java Domain Classes,只是为了保持一致并将所有内容保持在一起。使用POGO和POJO时,Grails没有问题,顺便说一句。

因此,从一个新的空数据库和一个新的空grails应用程序开始,我添加了Spring Security Plugin(acegi 0.5.1)。然后我做了:

grails create-auth-domains org.maflt.ibidem.pojo.Person org.maflt.ibidem.pojo.Authority org.maflt.ibidem.pojo.Requestmap

完美无缺。我创建的表格等等。然后我创建了POJO域类 并删除了POGO课程。然后一切编译得很好,但是当应用程序启动时我得到了这个错误:

2009-07-29 13:35:18,937 [main] ERROR context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        at java.security.AccessController.doPrivileged(Native Method)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
        at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:104)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:58)
        at RunApp$_run_closure1.doCall(RunApp:33)
        at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:344)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:334)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.processTargets(Gant.groovy:495)
        at gant.Gant.processTargets(Gant.groovy:480)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        at java.security.AccessController.doPrivileged(Native Method)
        ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        at java.security.AccessController.doPrivileged(Native Method)
        ... 24 more
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        ... 25 more
2009-07-29 13:35:18,968 [main] ERROR mortbay.log  - Failed startup of context org.mortbay.jetty.webapp.WebAppContext@1dfe1a{/sectest2,C:\src\netbeansprojects\sectest2/web-app}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        at java.security.AccessController.doPrivileged(Native Method)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
        at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:104)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:58)
        at RunApp$_run_closure1.doCall(RunApp:33)
        at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:344)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:334)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.processTargets(Gant.groovy:495)
        at gant.Gant.processTargets(Gant.groovy:480)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        at java.security.AccessController.doPrivileged(Native Method)
        ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        at java.security.AccessController.doPrivileged(Native Method)
        ... 24 more
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        ... 25 more
2009-07-29 13:35:19,031 [main] ERROR mortbay.log  - Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessController.doPrivileged(Native Method)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
        at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:104)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:58)
        at RunApp$_run_closure1.doCall(RunApp:33)
        at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:344)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:334)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.processTargets(Gant.groovy:495)
        at gant.Gant.processTargets(Gant.groovy:480)

我的POJO关注:

org.maflt.ibidem.pojo.Person

package org.maflt.ibidem.pojo;

import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;

/**
 * <p>Pojo mapping TABLE person</p>
 * <p></p>
 *
 * <p>Generated at Wed Jul 29 11:48:39 MDT 2009</p>
 * @author Salto-db Generator v1.0.16 / EJB3
 * 
 */
@Entity
@Table(name = "person", catalog = "test")
@SuppressWarnings("serial")
public class Person implements Serializable {

    /**
     * Attribute id.
     */
    private Long id;

    /**
     * Attribute version.
     */
    private Long version;

    /**
     * Attribute companyName.
     */
    private String companyName;

    /**
     * Attribute description.
     */
    private String description;

    /**
     * Attribute email.
     */
    private String email;

    /**
     * Attribute emailShow.
     */
    private Boolean emailShow;

    /**
     * Attribute enabled.
     */
    private Boolean enabled;

    /**
     * Attribute passwd.
     */
    private String passwd;

    /**
     * Attribute userRealName.
     */
    private String userRealName;

    /**
     * Attribute username.
     */
    private String username;

    /**
     * List of AuthorityPeople
     */
    private List<AuthorityPeople> authorityPeoples = null;


    /**
     * <p> 
     * </p>
     * @return id
     */
    @Basic
    @Id
    @GeneratedValue
    @Column(name = "id")
        public Long getId() {
        return id;
    }

    /**
     * @param id new value for id 
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * <p> 
     * </p>
     * @return version
     */
    @Basic
    @Column(name = "version")
        public Long getVersion() {
        return version;
    }

    /**
     * @param version new value for version 
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * <p> 
     * </p>
     * @return companyName
     */
    @Basic
    @Column(name = "company_name", length = 255)
        public String getCompanyName() {
        return companyName;
    }

    /**
     * @param companyName new value for companyName 
     */
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    /**
     * <p> 
     * </p>
     * @return description
     */
    @Basic
    @Column(name = "description", length = 255)
        public String getDescription() {
        return description;
    }

    /**
     * @param description new value for description 
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * <p> 
     * </p>
     * @return email
     */
    @Basic
    @Column(name = "email", length = 255)
        public String getEmail() {
        return email;
    }

    /**
     * @param email new value for email 
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * <p> 
     * </p>
     * @return emailShow
     */
    @Basic
    @Column(name = "email_show")
        public Boolean getEmailShow() {
        return emailShow;
    }

    /**
     * @param emailShow new value for emailShow 
     */
    public void setEmailShow(Boolean emailShow) {
        this.emailShow = emailShow;
    }

    /**
     * <p> 
     * </p>
     * @return enabled
     */
    @Basic
    @Column(name = "enabled")
        public Boolean getEnabled() {
        return enabled;
    }

    /**
     * @param enabled new value for enabled 
     */
    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    /**
     * <p> 
     * </p>
     * @return passwd
     */
    @Basic
    @Column(name = "passwd", length = 255)
        public String getPasswd() {
        return passwd;
    }

    /**
     * @param passwd new value for passwd 
     */
    public void setPasswd(String passwd) {
        this.passwd = passwd;
    }

    /**
     * <p> 
     * </p>
     * @return userRealName
     */
    @Basic
    @Column(name = "user_real_name", length = 255)
        public String getUserRealName() {
        return userRealName;
    }

    /**
     * @param userRealName new value for userRealName 
     */
    public void setUserRealName(String userRealName) {
        this.userRealName = userRealName;
    }

    /**
     * <p> 
     * </p>
     * @return username
     */
    @Basic
    @Column(name = "username", length = 255)
        public String getUsername() {
        return username;
    }

    /**
     * @param username new value for username 
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * Get the list of AuthorityPeople
     */
     @OneToMany(mappedBy="person")
     public List<AuthorityPeople> getAuthorityPeoples() {
        return this.authorityPeoples;
     }

    /**
     * Set the list of AuthorityPeople
     */
     public void setAuthorityPeoples(List<AuthorityPeople> authorityPeoples) {
        this.authorityPeoples = authorityPeoples;
     }


}

org.maflt.ibidem.pojo.Authority

package org.maflt.ibidem.pojo;

import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;

/**
 * <p>Pojo mapping TABLE authority</p>
 * <p></p>
 *
 * <p>Generated at Wed Jul 29 11:48:38 MDT 2009</p>
 * @author Salto-db Generator v1.0.16 / EJB3
 * 
 */
@Entity
@Table(name = "authority", catalog = "test")
@SuppressWarnings("serial")
public class Authority implements Serializable {

    /**
     * Attribute id.
     */
    private Long id;

    /**
     * Attribute version.
     */
    private Long version;

    /**
     * Attribute authority.
     */
    private String authority;

    /**
     * Attribute description.
     */
    private String description;

    /**
     * List of AuthorityPeople
     */
    private List<AuthorityPeople> authorityPeoples = null;


    /**
     * <p> 
     * </p>
     * @return id
     */
    @Basic
    @Id
    @GeneratedValue
    @Column(name = "id")
        public Long getId() {
        return id;
    }

    /**
     * @param id new value for id 
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * <p> 
     * </p>
     * @return version
     */
    @Basic
    @Column(name = "version")
        public Long getVersion() {
        return version;
    }

    /**
     * @param version new value for version 
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * <p> 
     * </p>
     * @return authority
     */
    @Basic
    @Column(name = "authority", length = 255)
        public String getAuthority() {
        return authority;
    }

    /**
     * @param authority new value for authority 
     */
    public void setAuthority(String authority) {
        this.authority = authority;
    }

    /**
     * <p> 
     * </p>
     * @return description
     */
    @Basic
    @Column(name = "description", length = 255)
        public String getDescription() {
        return description;
    }

    /**
     * @param description new value for description 
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Get the list of AuthorityPeople
     */
     @OneToMany(mappedBy="authority")
     public List<AuthorityPeople> getAuthorityPeoples() {
        return this.authorityPeoples;
     }

    /**
     * Set the list of AuthorityPeople
     */
     public void setAuthorityPeoples(List<AuthorityPeople> authorityPeoples) {
        this.authorityPeoples = authorityPeoples;
     }


}

org.maflt.ibidem.pojo.Requestmap

package org.maflt.ibidem.pojo;

import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;

/**
 * <p>Pojo mapping TABLE requestmap</p>
 * <p></p>
 *
 * <p>Generated at Wed Jul 29 11:48:39 MDT 2009</p>
 * @author Salto-db Generator v1.0.16 / EJB3
 * 
 */
@Entity
@Table(name = "requestmap", catalog = "test")
@SuppressWarnings("serial")
public class Requestmap implements Serializable {

    /**
     * Attribute id.
     */
    private Long id;

    /**
     * Attribute version.
     */
    private Long version;

    /**
     * Attribute configAttribute.
     */
    private String configAttribute;

    /**
     * Attribute url.
     */
    private String url;


    /**
     * <p> 
     * </p>
     * @return id
     */
    @Basic
    @Id
    @GeneratedValue
    @Column(name = "id")
        public Long getId() {
        return id;
    }

    /**
     * @param id new value for id 
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * <p> 
     * </p>
     * @return version
     */
    @Basic
    @Column(name = "version")
        public Long getVersion() {
        return version;
    }

    /**
     * @param version new value for version 
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * <p> 
     * </p>
     * @return configAttribute
     */
    @Basic
    @Column(name = "config_attribute", length = 255)
        public String getConfigAttribute() {
        return configAttribute;
    }

    /**
     * @param configAttribute new value for configAttribute 
     */
    public void setConfigAttribute(String configAttribute) {
        this.configAttribute = configAttribute;
    }

    /**
     * <p> 
     * </p>
     * @return url
     */
    @Basic
    @Column(name = "url", length = 255)
        public String getUrl() {
        return url;
    }

    /**
     * @param url new value for url 
     */
    public void setUrl(String url) {
        this.url = url;
    }



}

org.maflt.ibidem.pojo.AthorityPeople

package org.maflt.ibidem.pojo;

import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;

/**
 * <p>Pojo mapping TABLE authority_people</p>
 * <p></p>
 *
 * <p>Generated at Wed Jul 29 11:48:39 MDT 2009</p>
 * @author Salto-db Generator v1.0.16 / EJB3
 * 
 */
@Entity
@Table(name = "authority_people", catalog = "test")
@SuppressWarnings("serial")
public class AuthorityPeople implements Serializable {

    /**
     * Primary key
     */
    private AuthorityPeoplePK authorityPeoplePK;


    /**
     * Get the primary key
     */
    @Basic
    @Id
    public AuthorityPeoplePK getAuthorityPeoplePK() {
        return this.authorityPeoplePK;
    }

    /**
     * set the primary key
     */
    public void setAuthorityPeoplePK(AuthorityPeoplePK authorityPeoplePK) {
        this.authorityPeoplePK = authorityPeoplePK;
    }






    /**
          * <p>Composite primary key for table authority_people</p>
      *
      * <p>Generated at Wed Jul 29 11:48:39 MDT 2009</p>
      * @author Salto-db Generator v1.0.16 / EJB3
      */
    @SuppressWarnings("serial")
    @Embeddable
    public static class AuthorityPeoplePK implements Serializable {

        /**
         * Attribute authority
         */
         private Authority authority;   


        /**
         * Attribute person
         */
         private Person person; 


    /**
     * get authority
     */
            @ManyToOne
            @JoinColumn(name = "authority_id")
            public Authority getAuthority() {
                return this.authority;
            }

            /**
             * set authority
             */
            public void setAuthority(Authority authority) {
                this.authority = authority;
            }       
    /**
     * get person
     */
            @ManyToOne
            @JoinColumn(name = "person_id")
            public Person getPerson() {
                return this.person;
            }

            /**
             * set person
             */
            public void setPerson(Person person) {
                this.person = person;
            }       

        /**
         * calculate hashcode
         */
        @Override
        public int hashCode()
        {
            //TODO : implement this method
            return super.hashCode();
        }

        /**
         * equals method
         */
        @Override
        public boolean equals(Object object)
        {
            //TODO : implement this method
            return super.equals(object);
        }

    }

}

更新

看起来这个问题与AuthorityPeople有关。我添加了一个segregatey id键,使其成为主键并将对象更改为:

package org.maflt.ibidem.pojo;

import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;

/**
 * <p>Pojo mapping TABLE authority_people</p>
 * <p></p>
 *
 * <p>Generated at Wed Jul 29 19:34:03 MDT 2009</p>
 * @author Salto-db Generator v1.0.16 / EJB3
 * 
 */
@Entity
@Table(name = "authority_people", catalog = "test")
@SuppressWarnings("serial")
public class AuthorityPeople implements Serializable {

    /**
     * Attribute authority
     */
     private Authority authority;   

    /**
     * Attribute person
     */
     private Person person; 

    /**
     * Attribute id.
     */
    private Long id;


    /**
     * get authority
     */
    @ManyToOne
    @JoinColumn(name = "authority_id")
    public Authority getAuthority() {
        return this.authority;
    }

    /**
     * set authority
     */
    public void setAuthority(Authority authority) {
        this.authority = authority;
    }

    /**
     * get person
     */
    @ManyToOne
    @JoinColumn(name = "person_id")
    public Person getPerson() {
        return this.person;
    }

    /**
     * set person
     */
    public void setPerson(Person person) {
        this.person = person;
    }

    /**
     * <p> 
     * </p>
     * @return id
     */
    @Basic
    @Id
    @Column(name = "id")
        public Long getId() {
        return id;
    }

    /**
     * @param id new value for id 
     */
    public void setId(Long id) {
        this.id = id;
    }



}

现在我收到了这个错误:

java.lang.NullPointerException: Cannot invoke method list() on null object
        at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
        at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:750)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:727)
        at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite

2 个答案:

答案 0 :(得分:0)

  

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples

听起来像是一个Hibernate问题,而不是Spring Security或者你的POJO或grails。你在Person类中的这个:

@OneToMany(mappedBy="person")
public List<AuthorityPeople> getAuthorityPeoples() {
   return this.authorityPeoples;
}

您的注释是否指的是不正确的内容?

答案 1 :(得分:0)

我没有得到这个工作,直到现在,还没有看到任何其他人的证据。所以我采取了移动到grails对象。但我刚发现this solution。我还没有尝试过。我会在发布后发布结果。

顺便说一下 - 如果有人想再看看它,我仍然会对上面的实现提供帮助。