简体   繁体   中英

How to connect SQL server database with JPA project - Wildfly server - Java EE

Well, this question may be a duplicate or something. But I am desperate. I am learning Java EE and I cant even set up all the configurations properly.

My situation: I have a Wildfly 8.1- Jboss server, up and ready. I have deployed datasource (SQL server) Its working.

It has this JNDI:
java:/TimeTrackerDS

And this driver: sqlserver Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver

All this seems to be okay. Now I am deploying my new Application. And I just dont know how to use this staff to connect to database. The application is also deployed. How to connect these 2 things (db and app)

I have found a lot of solutions. Write properties to persistance.xml But I cant get anything to work. Because I don't understand it. Maybe if someone from you guys, show it to me on my particular example. I would understand what I am doing wrong.

(The server, app and sql server are all at same machine )(localhost)

I found the solution. I have a mistake in my entity java class. So it didnt compile properly. Propper persistence.xml for someone who may need it :

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

<persistence-unit name="TimeTracker">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>    

    <jta-data-source>java:/TimeTrackerDS</jta-data-source>
    <class>model.Task</class>
    <properties>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.jdbc.batch_size" value="20" />                        
        <property name="hibernate.format_sql" value="true"/>
    </properties>

</persistence-unit>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM