» »

java datapool - derby

java datapool - derby

boss-tech ::

V netbeans sem naredil derby bazo, tabele ter jdbc connection pool - kako potem v javi dostopam do tega connectiona in potem delam povpraševanja? Hvala

da2sn2 ::

v META-INF ustvaris persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
	<persistence-unit name="unit_name" transaction-type="JTA">
		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
		<jta-data-source>jdbc/pool_name</jta-data-source>
		<properties>
			<property name="eclipselink.logging.level" value="INFO"/>
			<property name="eclipselink.ddl-generation" value="create-tables"/>
		</properties>
	</persistence-unit>
</persistence>


nato v tvojem beanu uporabis

@PersistenceContext(unitName = "unit_name")
private EntityManager em;


isces pa z npr:

NekRazred obj = em.find(NekRazred.class, 1234); //1234=id


ali pa

String jpqlQuery = "SELECT c.objId FROM NekRazred c";
//
TypedQuery<Long> query = em.createQuery(jpqlQuery, Long.class);


EDIT: To gre za javo EE :)

lp

Zgodovina sprememb…

  • spremenil: da2sn2 ()

boss-tech ::

Imam samo WEB-INF, META-INF pa ni....gre za spletno aplikacijo

Zgodovina sprememb…

da2sn2 ::

Predvidevam da imas samo web module (zaradi WEB-INF; drugace lahko META-INF ustvaris rocno)?

V netbeansu ne vem kako tocno gre, v eclipsu pa ustvaris Dynamic Web Project za web in pa Enterprise Application Project s katerim dobis EJB modul (na koncu pa iz tega naredis ear datoteko (podobno kot jar), v kateri je zraven war modul in jo lahko deployas na aplication server). V EJB modulu nato ustvaris persistance.xml, itd..

Mogoce poglej na ta link ce bo kaj v pomoc: http://www.webagesolutions.com/knowledg...

boss-tech ::

Sedaj sem naredil en data library, ter v persistance.xml dal tole:

<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_2_0.xsd">
  <persistence-unit name="IzmenjavaDataLibraryPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>database.Izmenjava</class>
    <class>database.Student</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/izmenjavaDatabase"/>
      <property name="javax.persistence.jdbc.password" value="geslo"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="admin"/>
    </properties>
  </persistence-unit>
</persistence>


Potem pa zagnal test case kjer imam:


EntityManagerFactory emf = Persistence.createEntityManagerFactory("IzmenjavaDataLibraryPU");
EntityManager em = emf.createEntityManager();


Dobim pa napako:


Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)
at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:267)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:85)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369)
... 5 more
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)


Se pravi da moram dobit jar s tem razredom? Ali je v čem drugem problem

Zgodovina sprememb…

boss-tech ::

Jaz v aplikaciji kličem metodo, ki se poveže z bazo preko: EntityManagerFactory emf = Persistence.createEntityManagerFactory("test");
V aplikaciji lepo to gre skozi in vrne podatke. Ko pa zaženem main metodo iz tega projekta in kličem to metodo pa dobim:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named test
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)


Zakaj se to dogaja? Kje je razlika?

jlpktnst ::

javax.servlet.ServletException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform

Zabavno, če vržem v persistence.xml direkt jdbc driver dela. Če potegnem direkt jdbc/ connection pool v program tudi dela. Očitno eclipselink ne najde baze nekako? Verjetno so kekci nekaj spremenili in jit-data-source.../ property enostavno ne potegne zadeve not? Ali pa mi manjka driver nekje... pitaj boga, napaka je res useless.

Chain: eclipse 3.6, glassfish 3.1 integrated, eclipselink jpa, mysql. Če ma kdo kake ideje je ok, ker jih meni zmanjkuje :)


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[Java] JPA - transient v orm.xml

Oddelek: Programiranje
51031 (951) dmok
»

Ne zazna R.class -android

Oddelek: Programiranje
171301 (1139) Marat
»

tomcat in datasource

Oddelek: Programiranje
132026 (1783) infiniteLoop
»

Java- hibernate.properties not found

Oddelek: Programiranje
111794 (1294) xsenon
»

[java]package doesnt exist

Oddelek: Programiranje
6964 (847) <b>klima</b>

Več podobnih tem