1

I'm using eclipse with Jboss 6.0 server and the derby embedded driver. I created a database:

CREATE TABLE QUOTAZIONI.QuotazioniBancarie
(
Cliente VARCHAR(50) NOT NULL,
Prodotto VARCHAR(50) NOT NULL,
Prezzo DOUBLE NOT NULL,
Data DOUBLE NOT NULL,
CONSTRAINT primary_key PRIMARY KEY (Cliente, Prodotto, Prezzo, Data)
);

and using the JPA tools a entity associated to it: Quotazionibancarie.java and QuotazionibancariePK.java (there are 2 files cause it's a composite primary key)

The code fragment to persist the rows is the following:

.
.
.
@PersistenceContext(unitName = "P1Server")
private EntityManager em;
.
.
.
EntityTransaction et = em.getTransaction();
et.begin();
Quotazionibancarie q1 = new Quotazionibancarie(q.getCliente(), q.getProdotto(),        q.getPrezzo());          
em.persist(q1);
et.commit();

where the q class is a class I made for utility. The Data field is automatically generated.

When I try to save the content in the DB, the server doesn't give me any error but doesn't save the rows either.

11:36:02,710 INFO  [STDOUT] Hibernate: 
11:36:02,710 INFO  [STDOUT]     insert 
11:36:02,711 INFO  [STDOUT]     into
11:36:02,711 INFO  [STDOUT]         Quotazionibancarie
11:36:02,711 INFO  [STDOUT]         (cliente, data, prezzo, prodotto) 
11:36:02,711 INFO  [STDOUT]     values
11:36:02,711 INFO  [STDOUT]         (?, ?, ?, ?)

I searched on the forums but didn't manage to find any solution fit for my issue. Any idea of what causes my problem and how to fix it?

persistence.xml:

<?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_2_0.xsd">
    <persistence-unit name="P1Server" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/Quotazioni</jta-data-source>
        <class>entities.Quotazionibancarie</class>
        <class>entities.QuotazionibancariePK</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
        </properties>       
    </persistence-unit>
</persistence>

quotazioni-ds.xml

<?xml version="1.0" encoding="UTF-8" ?>
<datasources>
<local-tx-datasource>
    <!-- The jndi name of the DataSource, it is prefixed with java:/ -->
    <jndi-name>Quotazioni</jndi-name>
    <driver-class>org.apache.derby.jdbc.EmbeddedDriver</driver-class>
    <connection-url>jdbc:derby://localhost:1527/Quotazioni;create=true</connection-url>
    <user-name>root</user-name>
    <password>root</password>
    <min-pool-size>5</min-pool-size>
    <max-pool-size>20</max-pool-size>
    <idle-timeout-minutes>5</idle-timeout-minutes>
    <track-statements />
    <depends>jboss:service=Derby</depends>
</local-tx-datasource>

<mbean code="org.jboss.jdbc.DerbyDatabase" name="jboss:service=Derby">
    <attribute name="Database">Quotazioni</attribute>
</mbean>

</datasources>

Tell me if I need to specify some other informations.

Thx. Stefano

Kirkegoord
  • 11
  • 3

2 Answers2

0

your table is Quotazionibancarie or QuotazioniBancarie? may be that was the problem

  • as far as I know there is no case sensitive issue in this matter, cause all the different names are automatically generated. – Kirkegoord Feb 13 '12 at 11:51
0

Some common reasons for not successfully saving the data:

  1. You're actually getting an error returned from the database, but you're not checking for the error or are ignoring it somehow.
  2. You've set your application to autocommit=false, but never committed, so the database is rolling back your changes
  3. You are in fact saving the data, but when you go to look for it, you're not looking in the right place (wrong database, or the wrong schema inside the database), so you don't see the data when you go to look for it.

There are other reasons, but those are three good ones to check first.

Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
  • 1: how can I check if db is giving me errors apart for sourrounding the code in try/catch? 3: i'm sure I'm looking in the right place. 2: could u enlighten me more on this second point? Thank for the reply – Kirkegoord Feb 13 '12 at 16:37
  • A good place to start is to find the 'derby.log' file that your Derby server is writing, and practice reading it. Once you find that log and become comfortable reading it, you can enable more information to be written there. For example, turn on derby.language.logstatementtext: http://db.apache.org/derby/docs/10.8/ref/rrefproper43517.html – Bryan Pendleton Feb 13 '12 at 21:12
  • I found 3 differet derby.log files, one in DERBY_HOME/bin, one in JBOSS_HOME/bin and one in ECLIPSE_HOME; no one of them writes anything about the transaction I try to do, even after modifying the derby.preoperties with the logstatementtext – Kirkegoord Feb 15 '12 at 15:07
  • The derby.log file gets written in Derby's home directory when it's run, and that's where Derby generally looks for its databases. Did you look in the location where you start the Derby network server? – Bryan Pendleton Feb 15 '12 at 19:26
  • yes, but the only information it writes are the one on the location, data and start. – Kirkegoord Feb 15 '12 at 20:28
  • And you still can't get any extra information from derby.language.logstatementtext? You might find it useful to go through this book: http://db.apache.org/derby/docs/10.8/getstart/ It will help you get more comfortable with Derby. – Bryan Pendleton Feb 15 '12 at 22:40