Announcement Announcement Module
Collapse
No announcement yet.
Roo Integration test fail hibernate.MappingException:component property not found: id Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Roo Integration test fail hibernate.MappingException:component property not found: id

    I cannot figure out what is missing with JPA entity generated by Roo, I get the following exception
    Caused by: org.hibernate.MappingException: component property not found: id
    at org.hibernate.mapping.Component.getProperty(Compon ent.java:292)
    at org.hibernate.cfg.AnnotationBinder.fillComponent(A nnotationBinder.java:2455)
    at org.hibernate.cfg.AnnotationBinder.fillComponent(A nnotationBinder.java:2336)

    so the test fails with java.lang.IllegalStateException: Failed to load ApplicationContext

    I have a simple JPA Roo entity as follows

    @RooJavaBean
    @RooToString
    @RooJpaEntity
    public class Customer {

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Calendar enrollmentDate;

    private String identifier;

    private String name;

    private String countryOfResidence;

    @Embedded
    private PostalAddress postalAddress;

    @ManyToMany(cascade = CascadeType.ALL)
    private Set<Account> accounts = new HashSet<Account>();

    @Autowired
    private transient MailSender primaryEmail;

    public void sendMessage(String mailFrom, String subject, String mailTo, String message) {
    org.springframework.mail.SimpleMailMessage mailMessage = new org.springframework.mail.SimpleMailMessage();
    mailMessage.setFrom(mailFrom);
    mailMessage.setSubject(subject);
    mailMessage.setTo(mailTo);
    mailMessage.setText(message);
    primaryEmail.send(mailMessage);
    }
    }

    I generated integration tests for it using roo shell so first I do see correct Customer_Roo_Jpa_Entity.aj generated below
    privileged aspect Customer_Roo_Jpa_Entity {

    declare @type: Customer: @Entity;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long Customer.id;

    @Version
    @Column(name = "version")
    private Integer Customer.version;

    public Long Customer.getId() {
    return this.id;
    }

    public void Customer.setId(Long id) {
    this.id = id;
    }

    public Integer Customer.getVersion() {
    return this.version;
    }

    public void Customer.setVersion(Integer version) {
    this.version = version;
    }

    }

    I have attached the META-INF folder here that contains my spring config and the persistence xml also attached is the text output from the test run

  • #2
    Use the Roo 'backup' command and attach the whole project. I need PostalAddress.java and Account.java to attempt to reproduce the issue.

    Comment


    • #3
      Thanks Alex, I found the issue, one of my entity has embedded object and there are multiple attributes of the same type its the Typical Person has to "Address" fields one is the property of "homeAddress" and other "workAddress" so I'm now in the process of using @AttributeOverrides to fix the column names for it

      I do have a question about entity Mapping for you,

      For Account there are 2 types of objects, one is an Account object that needs to be embeddable inside like a Payment objects whereas another type of Account has to be a ManyToMany relationship with Customer, they have exactly same attributes so what is your recommendation for this model? since I cannot have one Account entity that can do both, should I have Parent class Account and then 2 child entity classes CashAccount (embeddable) and CustomerAccount(m to m relationship with Customer)

      I'm using the documentation from this link to fix my error with the tests
      http://docs.jboss.org/hibernate/stab...single/#d0e714

      Comment

      Working...
      X