-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate could not resolve property error
PostPosted: Sat Jun 21, 2014 1:40 pm 
Newbie

Joined: Sat Jun 21, 2014 1:34 pm
Posts: 1
Hello

I am currently getting absolutely bally nowhere with a problem with Hibernate where I am given the message:

Code:
Your page request has caused a QueryException: could not resolve property: PERSON_ID of: library.model.Person [FROM library.model.Person p JOIN Book b ON p.PERSON_ID = b.PERSON_ID WHERE p.PERSON_ID = 2] error:


In the method below:

Code:
@Override
    public Person getPersonAndBooks(Integer personId) {
        logger.info(PersonDAOImpl.class.getName() + ".listBooksForPerson() method called.");
       
        Session session = sessionFactory.openSession();                 
        Query query = session.createQuery("FROM Person p JOIN Book b ON p.PERSON_ID = b.PERSON_ID WHERE p.PERSON_ID = " + personId);               
        List<Person> persons = query.setResultTransformer(Transformers.aliasToBean(Person.class)).list();
        List<Book> books = persons.get(0).getBooks();
            for (Book b : books) {
               System.out.println("Here " + b.toString());
            }   
            return persons.get(0); 
        }       
        finally {
            session.close();
        }         
    }


But I see nothing wrong in the SQL and it works perfectly well in Apache Derby.

I've tried a number of things on StackOverflow and elsewhere but nothing resolves the issue.

There are two classes in a simple application:

Code:
@Entity
    @Table(name = "PERSON")
    public class Person implements Serializable {
   
    // Attributes.   
    @Id
    @Column(name="PERSON_ID", unique=true, nullable=false)   
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer personId;
   
    @Column(name="NAME", nullable=false, length=50)     
    private String name;

    @Column(name="ADDRESS", nullable=false, length=100)
    private String address;

    @Column(name="TELEPHONE", nullable=false, length=10)
    private String telephone;
   
    @Column(name="EMAIL", nullable=false, length=50)
    private String email;
   
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)     
    private List<Book> books;


And Book:

Code:
@Entity
    @Table(name = "BOOK")
    public class Book implements Serializable {
   
    // Attributes.
    @Id
    @Column(name="BOOK_ID", unique=true, nullable=false)
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer bookId;
   
    @Column(name="AUTHOR", nullable=false, length=50)
    private String author;
   
    @Column(name="TITLE", nullable=false, length=50)
    private String title;
   
    @Column(name="DESCRIPTION", nullable=false, length=500)
    private String description;
   
    @Column(name="ONLOAN", nullable=false, length=5)
    private String onLoan;
     
    @ManyToOne
    @JoinColumn(name="person_id")   
    private Person person;


Each maps to database tables:

Code:
    CREATE TABLE PERSON (
      PERSON_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),   
      NAME VARCHAR(50) NOT NULL, 
      ADDRESS VARCHAR(100) NOT NULL,
      TELEPHONE VARCHAR(10) NOT NULL,
      EMAIL VARCHAR(50) NOT NULL,     
      CONSTRAINT PRIMARY_KEY_PERSON PRIMARY KEY(PERSON_ID)
    )


And Book is:

Code:
CREATE TABLE BOOK (
      BOOK_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),   
      AUTHOR VARCHAR(50) NOT NULL, 
      TITLE VARCHAR(100) NOT NULL,
      DESCRIPTION VARCHAR(500) NOT NULL,
      ONLOAN VARCHAR(5) NOT NULL,
      PERSON_ID INTEGER,   
      CONSTRAINT PRIMARY_KEY_BOOK PRIMARY KEY(ID),
      CONSTRAINT FOREIGN_KEY_BOOK FOREIGN KEY(PERSON_ID) REFERENCES PERSON(PERSON_ID) 
    )



Can someone please tell me where I am going wrong?

And if when the SQL finally works, if I am using the right method to convert the output into a Person object where a Person has an arraylist of Book?

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.