开发者

Table is not mapped?

Now to my understanding to map a table in db we add:

@Entity()
@Table(name = "test")
public class Test implements Serializable {
    /** Constant - serial version UID. */
    public final static long serialVersionUID = 1L;

    /** Member variable - represents the "name" field. */
    public String name;
}

but for some reason when I do query:

delete from test;

it gives me this error:

15:55:54,140 ERROR [JsonFilter] javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: spa_splash_page_ad is not mapped [delete from spa_splash_page_ad]
javax.servlet.ServletException: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: spa_splash_page_ad is not mapped [delete from spa_splash_page_ad]
    at com.pinksheets.common.web.servlet.DeleteSplashPageServlet.fetch(DeleteSplash开发者_Python百科PageServlet.java:30)
    at com.pinksheets.common.web.servlet.DeleteSplashPageServlet.fetch(DeleteSplashPageServlet.java:17)

any idea why it is doing that?


  1. Try:

    delete from com.mycompany.database.Test
    read about fully qualified names (it is the full package name/path + the class name )

  2. Why is the word table in the query?

  3. Also remove the () from the @Entity()

  4. you should keep the java convention, name your entities with capital starting letters:

    class Test{} than you can:

    delete from fully.qualified.name.Test

  5. Make sure the the Entity is @javax.persistence.Entity and not something else.


delete from table test isn't a valid query in any QL I know of.

A class mapped as @IdClass is a composite id, and you'd never delete it directly. You would delete an entity that has that as its id. Also since it's an @IdClass, I'm not sure what to expect when you give it an explicit @Table mapping. An @IdClass is a primary key value and is always supposed to be used as an id of some other class. It doesn't have its own table. See the hibernate annotations reference for mapping composite ids and correct use of @IdClass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜