27 Ekim 2009 Salı

revisited : Troobleshooting: Date becomes XMLGregorianCalendar when stubs are generated at client side, how to prevent this?

lets revisit issue on http://hilaltarakci.blogspot.com/2009/06/troobleshooting-date-becomes.html
the problem is, although adapter interface is generated, the generated implementation for the interface is empty.. so, sould replace with own implementation..

btw, soln is discovered by someone in the team, not me.. lets share it :  https://jaxb.dev.java.net/guide/Using_different_datatypes.html


18 Ekim 2009 Pazar

Could not execute JDBC batch update

the error Could not execute JDBC batch update comes out when the entities are as follows and you are trying to save the parent entity:

parent entity
  @OneToMany(cascade = CascadeType.ALL)
   @JoinTable(name = "TBL_INCIDENT_ABSEVIDGRP", joinColumns = {
        @JoinColumn(name = "FLD_INCIDENT_ID")
    },
    inverseJoinColumns = {
        @JoinColumn(name = "FLD_ABSEVIDGRP_ID")
    })
private List childList = new ArrayList();

child entity
    @ManyToOne
    @JoinTable(name = "TBL_INCIDENT_ABSEVIDGRP", joinColumns = {
        @JoinColumn(name = "FLD_ABSEVIDGRP_ID")
    },
    inverseJoinColumns = {
        @JoinColumn(name = "FLD_INCIDENT_ID")
    })
private Parent parent;

the error is solved by commenting out the green and bold code portion..
the lack of red code portion leads to the following error while saving the parent entity:
Error while commiting the transaction
javax.persistence.RollbackException: Error while commiting the transaction
        at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
...
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Child Entity
 

unit testing dao with actual postgre db settings

the environment is netbeans 6.5 ide, postgre db, junit for unit testing..
when i try to execute unit tests over postgre, i get the following error:
3196 [main] FATAL org.hibernate.connection.DatasourceConnectionProvider  - Could not find datasource: blshilaltarakci
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
....

i think the reason for this is the lack of jndi properties file. when the project is deployed to any server, the server mostly already has a jndi properties file and this is not a problem..  ( i think..) in my case, there is no jndi properties file in classpath, since the (dao) project is not deployed to server in the time of testing.. 
so, i moved back to unit testing using an in memory database..

Edit on 05/11/2009 at 10:27 : Sometimes, the reason the error does not disappear is badly formed named queries.. 

15 Ekim 2009 Perşembe

soapui experience

well, i want to note down what i faced unexpected during my soapui usage..

first of all, soapui project is one big xml file which is a disadvantage.. i really have no idea how they handled svn usage, maybe it is similar to enterprise architect's solution. whatever, my concern is not svn at this moment..

secondly, i could not open the project after i closed netbeans, i don t know why.. soapui-project.xml file is just got emty with no reason.. so, i have to start from beginning, this is annoying actually :( the point is: pay special attention to taking backups..
and this warning comes up everytime i close netbeans.. 
Project file [...Test] has been modified externally, overwrite?

TODO: very soon..



13 Ekim 2009 Salı

soapui

well, lets start with testing web services using soapui
in a previous post at http://hilaltarakci.blogspot.com/2009/10/web-service-testing-in-netbeans.html a quick start has been made.. now, it is time to continue..
the following are good tutors to start up:

soapui vs jmeter for web service testing

this article is a good comparison of jmeter and soapui (and lucily a recent one) : http://www.developer.com/open/article.php/3839476/article.htm

according to this, soapui wins for two main reasons:
  •  from the article: A big difference from the SoapUI here is that you should have SOAP requests already to be supplied to JMeter, where as in SoapUI you can generate them.
this is a big deal in fact..
  • again from  the article: The learning curve of SoapUI is shorter then the JMeter, mostly because SoapUI automates a lot of tasks related to the creation of the Web services test plans.
 we are in a hurry, so shorter learning curve is attractive..

web service testing in netbeans

i have been looking for some tool to test (jax ws) web services developped with netbeans 6.5.  soapui at http://www.soapui.org/ is such a tool.. It is both available as standalone or as netbeans plugin.. well, i prefer the plugin (http://www.soapui.org/netbeans/index.html).. 
lets begin..

the very first step is installing the plugin.. just download the nbm from http://sourceforge.net/projects/soapui/files/soapui-netbeans-plugin/3.0 and follow the instructions at http://www.soapui.org/netbeans/installation.html


so, end of the quick start.. 

Edit on 13/10/2009 at 11.12 : 
btw, the command line tools of soapui does not come with the plugin.. so, if you want to use them, for instance launch testrunner inside netbeans or whatever, download soapui standalone version from http://sourceforge.net/projects/soapui/files/soapui/3.0.1 , run the executable for installation, and show the path soapUI-3.0.1/bin for testrunner exe or something..

Edit on 13/10/2009 at 12.03 :
moreover, it is possible to test bpel processes with soapui..
here are the examples:

6 Ekim 2009 Salı

notes on schuchert jpa tutor 4

finally the last tutor at http://schuchert.wikispaces.com/JPA+Tutorial+4+-+Inheritance+and+Polymorphic+Queries

lets move!
now, all tests should pass..
well, time to go to my own project, thanks to schuchert, tutors are really helpful :)

notes on schuchert jpa tutor 3

now the tutor i follow is http://schuchert.wikispaces.com/JPA+Tutorial+3+-+A+Mini+Application

lets see what happens..

so perfect, just in test methods of LibraryTest, the assertEquals methods used to compare floats that take 2 params are deprecated. Instead define a delta as follows and pass it as 3rd param to mentioned methods. Thus, tests will pass i think :)
private static final float DELTA = (float) 0.0;
...
assertEquals(.., .., DELTA);




5 Ekim 2009 Pazartesi

notes on schuchert jpa tutor 2

the tutor is at http://schuchert.wikispaces.com/JPA+Tutorial+2+-+Working+with+Queries+1

lets follow..
  • comment out the exception in the  unsuccessfulSingleResultTooManyEntries  test case of QueriesTest.. thus, it will pass..
 @Test// (expected = NonUniqueResultException.class)
    public void unsuccessfulSingleResultTooManyEntries() {
insertPerson();
        insertPerson();

        // This will fail because we expect a single result
        // but in fact there are 2 results returned.
        em.createQuery("from Person").getSingleResult();
    }

this is because,  getSingleResult() does not get angry when there are more than one records and just picks the first one..



4 Ekim 2009 Pazar

notes on schuchert jpa tutor 1

i am following schuchert's jpa tutor 1 at http://schuchert.wikispaces.com/JPA+Tutorial+1+-+Getting+Started
however, my environment is netbeans 6.5 + glassfish v2 + postgre..
lets note down some drawbacks i faced:
  • i get the following error while trying to run PersonTest :
Testcase: emptyTest(entity.PersonTest):        Caused an ERROR
[PersistenceUnit: SchuchertJpaTutor1PU] Unable to build EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: SchuchertJpaTutor1PU] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at entity.PersonTest.initEmfAndEm(PersonTest.java:24)
Caused by: org.hibernate.HibernateException: Could not find datasource
        at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
        at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
        at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)

Testcase: emptyTest(entity.PersonTest):        Caused an ERROR
null
java.lang.NullPointerException at entity.PersonTest.cleanup(PersonTest.java:31)
Test entity.PersonTest FAILED

to fix:
- use in memory database in unit tests with persistence.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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="SchuchertJpaTutor1TestPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source></non-jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:unit-testing-jpa"/>
        <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
        <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        <property name="hibernate.connection.username" value="sa"/>
        <property name="hibernate.connection.password" value=""/>
    </properties>
  </persistence-unit>
</persistence>
- add hsqldb.jar and (possibly) servlet.jar to test libs 

and run the test again, it should pass now..

  • when Address is added to Person, delete the final keyword from getter and setter methods for address.(it results in compile error..)

i will continue with the next tutorial, so see you at the next blog entry :)