futurefire
futurefire
2009-07-09 11:51

JPA最基础的例子问题

  • hibernate

小弟今天才开始学习JPA

1.在oracle下建了一张employee表:id,name,salary

2.建一个实体
package examples.model;

@Entity
public class Employee {
@Id
private int id;
private String name;
private long salary;

public Employee() {
}
    ...省了get()和set()
    }

3.presistence.xml

examples.model.Employee







问题:@Entity为什么提示我The table Employee cannot be found on the database
可是我有这张表了啊,为什么啊?
[b]问题补充:[/b]
orcale中分大小写吗?
[b]问题补充:[/b]
我是不是那个地方没有配置对?
[b]问题补充:[/b]
刚才那个问题重起了一下eclipse就没了
一运行测试类就出这个异常时说明原因
测试类:
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("EmployeeService");
EntityManager em = emf.createEntityManager();
EmployeeService service = new EmployeeService(em);

    em.getTransaction().begin();
    Employee emp = service.createEmployee(158, "John Doe", 45000);
    em.getTransaction().commit();
    System.out.println("Persisted:" + emp);

异常:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named EmployeeService
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at EmployeeTest.main(EmployeeTest.java:11)
[b]问题补充:[/b]
配置文件不是放在src/META-INF/persistence.xml???
为什么找不到?
[b]问题补充:[/b]

oracle.toplink.essentials.PersistenceProvider

加上这句也不行啊,你们谁有一个简单jpa的例子,发个我,我照着做一下
怎么也要先弄个jpa的helloworld出来啊!~~~

邮箱:lovellj2002@163.com
[b]问题补充:[/b]
经过一番折腾
异常换成

指定了无效的 Oracle URL
我的oracle驱动是ojbc14.jar
oracle.jdbc.OracleDriver 这个不对?
[b]问题补充:[/b]
jdbc:oracle:thin:@localhost:1521:ZFKGL

哥们成功了!~~谢谢各位太高兴了

刚才少了个:

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答

为你推荐