我正在試圖解決大學的Java編程練習,但我不知道如何解決下一個問題。我有下一個persistence.xml文件:JPA從數據庫檢索對象
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="stud" transaction-type="RESOURCE_LOCAL">
<class>lt.vu.mif.jate.tasks.task03.jpa.model.Customer</class>
<class>lt.vu.mif.jate.tasks.task03.jpa.model.Product</class>
<class>lt.vu.mif.jate.tasks.task03.jpa.model.Sale</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.NoCacheProvider"/>
<property name="hibernate.generate_statistics" value="false"/>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://****************"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="hibernate.hbm2ddl.auto" value="none"/>
</properties>
</persistence-unit>
</persistence>
數據庫的URL在這裏只是ommited。我無法更改此文件。我必須連接到數據庫並從數據庫獲取所有數據。我已經創建了所需的三個類。我該怎麼做?非常感謝。
您是否瞭解jpql? –
我知道是用於查詢的java語言。但現在我甚至沒有與數據庫共存。 –
問題到底是什麼?您無法獲得與數據庫的連接,或者您無法使用該連接獲取任何有用的連接? – Tobb