English 中文(简体)
查询例外:无法解决属性
原标题:org.hibernate.QueryException: could not resolve property
  • 时间:2012-05-27 19:26:16
  •  标签:
  • java
  • jpa

这是我第一次使用JPA 我和Java和JPA一起写代码 我的代码在下面

 String queryStr = "SELECT m.title, b.isbn, b.authors";
    queryStr += " FROM Book b, Media m";
    queryStr += " WHERE m.MediaID = b.MediaID";
            queryStr += " AND b.isbn =  " + isbn + "  AND m.title =  %" + title +"% "; 
Query query = em.createQuery(queryStr);

从我的代码, 班本扩展类媒体。

但我有错误

无法解决财产问题:介质管理. Media[SELECT m.标题,b.isbn, b. 媒体管理机构的作者.bookb, 媒体管理机构. Mediamidiam where m. MediaID = b. MediaID]

这是媒体课

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "Media")
@NamedQuery(name = "findAllMedias", query = "select b from Media b")
public class Media {

@Id
@Column(name = "MediaID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int mediaID;

/**
 * Getter of the property <tt>mediaID</tt>
 * 
 * @return Returns the mediaID.
 * @uml.property name="mediaID"
 */
public int getMediaID() {
    return mediaID;
}

/**
 * Setter of the property <tt>mediaID</tt>
 * 
 * @param mediaID
 *            The mediaID to set.
 * @uml.property name="mediaID"
 */
public void setMediaID(int mediaID) {
    this.mediaID = mediaID;
}

/**
 * @uml.property name="title"
 */
@Column(name = "title")
private String title;

/**
 * Getter of the property <tt>title</tt>
 * 
 * @return Returns the title.
 * @uml.property name="title"
 */
public String getTitle() {
    return title;
}

/**
 * Setter of the property <tt>title</tt>
 * 
 * @param title
 *            The title to set.
 * @uml.property name="title"
 */
public void setTitle(String title) {
    this.title = title;
}

/**
 * @uml.property name="editionDate"
 */

private Calendar editionDate;

/**
 * Getter of the property <tt>editionDate</tt>
 * 
 * @return Returns the editionDate.
 * @uml.property name="editionDate"
 */
public Calendar getEditionDate() {
    return editionDate;
}

/**
 * Setter of the property <tt>editionDate</tt>
 * 
 * @param editionDate
 *            The editionDate to set.
 * @uml.property name="editionDate"
 */
public void setEditionDate(Calendar editionDate) {
    this.editionDate = editionDate;
}

/*
 * Two medias are equal if their mediaID is the same
 */
@Override
public boolean equals(Object media) {
    if (media == null)
        return false;
    Media b = (Media) media;

    if (b.mediaID == mediaID)
        return true;

    return false;
}

public Media() {
};

/**
 * Creates a media All parameters should be given
 * 
 * @param title
 *            the title of the media
 * 
 * @param editionDate
 *            date of the edition of the media
 * 
 * @throws BadParametersException
 */
public Media(String title, Calendar editionDate)
        throws BadParametersException {
    if ((title == null) || (editionDate == null))
        throw new BadParametersException();

    this.title = title;
    this.editionDate = editionDate;

}

/**
 * Returns a description of the media
 */
public String toString() {
    return this.title + "  " + String.valueOf(this.title);
}

/** 
 * @uml.property name="copies"
 * @uml.associationEnd multiplicity="(0 -1)" inverse="media:copyManagement.Copy"
 */
@OneToMany(mappedBy="mediaRef") protected Set<Copy> copies;

public void addCopy(Copy copy) {
    copies.add(copy);
}

/** 
 * Getter of the property <tt>copies</tt>
 * @return Returns the copies.
 * @uml.property name="copies"
 */
public Set<Copy> getCopies() {
    return copies;
}

/** 
 * Setter of the property <tt>copies</tt>
 * @param editionDate The copies to set.
 * @uml.property  name="copies"
 */
public void setCopies(Set<Copy> copies) {
    this.copies = copies;
}

这是书课

@Entity
@Table(name = "Book")
@NamedQuery(name = "findAllBooks", query = "select b from Book b")
public class Book extends Media {
/**
 * @uml.property name="authors"
 */
@Column(name = "authors")
private ArrayList<String> authors;

/**
 * Getter of the property <tt>authors</tt>
 * 
 * @return Returns the authors.
 * @uml.property name="authors"
 */
public ArrayList<String> getAuthors() {
    return authors;
}

/**
 * Setter of the property <tt>authors</tt>
 * 
 * @param authors
 *            The authors to set.
 * @uml.property name="authors"
 */
public void setAuthors(ArrayList<String> authors) {
    this.authors = authors;
}

/**
 * @uml.property name="isbn"
 */

@Column(name = "isbn")
private String isbn;

/**
 * Getter of the property <tt>isbn</tt>
 * 
 * @return Returns the isbn.
 * @uml.property name="isbn"
 */
public String getisbn() {
    return isbn;
}

/**
 * Setter of the property <tt>isbn</tt>
 * 
 * @param isbn
 *            The isbn to set.
 * @uml.property name="isbn"
 */
public void setisbn(String isbn) {
    this.isbn = isbn;
}

public Book() {
    // TODO Auto-generated constructor stub
}

public Book(String title, Calendar editionDate, ArrayList<String> authors,
        String isbn) throws BadParametersException {
    super(title, editionDate);
    this.authors = authors;
    this.isbn = isbn;
    // TODO Auto-generated constructor stub
}

}

谁能帮上忙?

问题回答

如果书籍扩展媒体,你为什么要加入媒体表? (尽管用书籍和媒体课程和绘图比较容易)

查询“ book” 对象应该足够了 。 也许“ MediaId” 应该是“ mediaID ” 。 Hibernate 是在它的属性名称上比较敏感的 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签