[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Question regarding odd behavior of EclipseLink with Derby
|
Hi Tom,
I agree with you that Derby and PostgreSQL both succeed in persisting the 'Service' object into the database.
Yes, I am running more queries as part of a JUnit test and those queries seem to be causing the exception. I have attached the relevant portions of the code and the relevant queries in the file code.txt.
To answer you other questions...
1. In the attached code.txt file, I mention what code runs before the queries run and what code runs after those queries run.
2. There is nothing that modifies an object and does a flush or commit after the queries are run. Please see attached code.txt for more information.
Thank you,
Gopi
/*
Hi Tom,
The 'testGetAllEndpoints_countEndpointsForAdmin' method is a JUnit test and
it invokes the 'getAllEndpoints' method which in turn invokes the
'getServicesAtEndpoint' method. All the three methods are included below.
They use named queries from my orm.xml file which are also included below.
Before each test is run, the setUp() method is called, which in turn calls
super.setUp() which basically creates empty tables. The super.tearDown()
basically drops all tables
*/
@Before
public void setUp() {
super.setUp();
user1 = util.createUserAccount("user1");
user2 = util.createUserAccount("user2");
endpoint1 = util.createEndpoint("endpoint1", user1);
endpoint2 = util.createEndpoint("endpoint2", user2);
serviceType1 = util.createServiceType("gsiftp");
try {
service1 = util.createService("hostName1", 1234, endpoint1, serviceType1, user1);
} catch (GlobusOrgException e) {
logger.fatal(e.getMessage());
}
}
@After
public void tearDown() {
super.tearDown();
}
@Test
public void testGetAllEndpoints_countEndpointsForAdmin() {
QualifierImpl q = new QualifierImpl();
q.setIsAdmin(true);
EndpointQualifiedList endpoints = impl.getEndpointDataSource().getAllEndpoints("user1", q);
assertEquals(2, endpoints.getCount());
assertEquals(2L, endpoints.getTotal());
}
@SuppressWarnings("unchecked")
public EndpointQualifiedList getAllEndpoints(String userName, Qualifier q) {
Query query = em.createNamedQuery("Endpoint.countEndpoints");
List<Endpoint> results = new ArrayList<Endpoint>();
long total = ((Long) query.getSingleResult()).longValue();
if (total > 0) {
if (q.isAdmin()) {
query = em.createNamedQuery("Endpoint.getAllEndpointsForAdmin");
} else {
query = em.createNamedQuery("Endpoint.getAllEndpointsForUser");
query.setParameter("userName", userName);
}
query.setFirstResult(q.getOffset());
if (q.getLimit() != -1) {
query.setMaxResults(q.getLimit());
}
results = query.getResultList();
for (Endpoint endpoint : results) {
Qualifier q1 = new QualifierImpl();
endpoint.addServices(getServicesAtEndpoint(endpoint, q1).getList());
}
}
return new EndpointQualifiedList(results, q, total);
}
@SuppressWarnings("unchecked")
public ServiceQualifiedList getServicesAtEndpoint(Endpoint endpoint, Qualifier q) {
Query query = em.createNamedQuery("Service.countServicesAtEndpoint");
query.setParameter("id", endpoint.getId());
long total = ((Long) query.getSingleResult()).longValue();
query = em.createNamedQuery("Service.getServicesAtEndpoint");
query.setParameter("id", endpoint.getId());
query.setFirstResult(q.getOffset());
if (q.getLimit() != -1) {
query.setMaxResults(q.getLimit());
}
List<Service> services = query.getResultList();
return new ServiceQualifiedList(services, q, total);
}
These are the named queries in the orm.xml file that are run by the above methods
<named-query name="Service.getServicesAtEndpoint">
<query>SELECT s FROM Service s WHERE s.endpoint.id = :id</query>
</named-query>
<named-query name="Service.countServicesAtEndpoint">
<query>SELECT COUNT(s) FROM Service s WHERE s.endpoint.id = :id</query>
</named-query>
<named-query name="Endpoint.getAllEndpointsForAdmin">
<query>SELECT e FROM Endpoint e</query>
</named-query>
<named-query name="Endpoint.getAllEndpointsForUser">
<query>SELECT e FROM Endpoint e WHERE e.user.name = :userName</query>
</named-query>
On Jan 20, 2010, at 10:48 AM, Tom Ware wrote:
> Hi Gopi,
>
> From what I can see, Derby and PostgreSQL are succeeding at running exactly the same SQL. Derby simply runs code after the successful code that causes the failure.
>
> Can you please post the code you are running in both environments? When I look at the logs, I see a successful INSERT - perhaps the result of your persist. After the insert, the transaction commits, and more SQL is run. Are you running some queries? ("Service.countServicesAtEndpoint", "Service.getServicesAtEndpoint") What do those queries do? What code is run around the times when those queries are run? What happens after those queries are run (is there something that modifies an object and either does a flush of a commit?
>
>
>
> -Tom
>
> Gopi Kandaswamy wrote:
>> Hi Tom,
>> Thank you for your help. Please find attached two files; one with the derby logs (derby-log.txt) and the other with the postgresql logs (postgres-log.txt). As I had mentioned before, the problem occurs when I try to persist the 'Service' object and so I have included the logs for just that. As you can see the persist operation works fine in postgresql but fails in derby.
>> Note: 1. The relation between Service (maps to table called physical_endpoints) and Endpoint (maps to table logical_endpoints) is of type 'many-to-one' as specified in the orm.xml.
>> 2. I have attached the relevant portions of my pom.xml file (pom.xml) to tell you which versions of what libraries I am using.
>> Thank you very much in advance.
>> Gopi
>> ------------------------------------------------------------------------
>> ------------------------------------------------------------------------
>> ------------------------------------------------------------------------
>> On Jan 20, 2010, at 7:09 AM, Tom Ware wrote:
>>> Hi Gopi,
>>>
>>> Could you turn on logging and send the logged SQL from both your Derby and PostGreSQL test cases? (persistence unit property: eclipselink.logging.level=FINEST)
>>>
>>> Please also include the full stack trace from the exception in Derby.
>>>
>>> -Tom
>>>
>>> Gopi Kandaswamy wrote:
>>>> Hi all,
>>>> I am using EclipseLink 2.1.0 and when I run my code against a Derby database, I get the following error message. Basically this is what is happening...
>>>> a) I have a class called 'Service' (maps to database table called physical_endpoints) which has a many-to-one relationship to a database table called logical_endpoints. So the orm.xml for physical_endpoints looks like this...
>>>> <entity class="Service">
>>>> <table name="physical_endpoints" />
>>>> <attributes>
>>>> .
>>>> .
>>>> .
>>>> <many-to-one name="endpoint">
>>>> <join-column name="logical_id" />
>>>> </many-to-one>
>>>> </attributes>
>>>> </entity>
>>>> As you can see, I have specified a <join-column name="logical_id">. I have not specified a <join-table name="the_join_table_name"> because such a join table does not exist and I do not want such a table to be created automatically by JPA. But when I run my code, EclipseLink tries to insert records into the join table for the above relationship. The join table for the above relation does not exist and hence the error below. The weird thing here is that when I use PostgreSQL database instead of Derby database, the following exception does not occur. In other words, the error occurs when I use EclipseLink + Derby and not EclipseLink + PostgreSQL.
>>>> Does anyone have any ideas? The error below occurs when I persists (em.persist(service)) to the database.
>>>> Thanks
>>>> Gopi
>>>> =======Exception=========
>>>> Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'LOGICAL_ENDPOINTS_PHYSICAL_ENDPOINTS' does not exist.
>>>> Error Code: 20000
>>>> Call: INSERT INTO logical_endpoints_physical_endpoints (services_id, Endpoint_id) VALUES (?, ?)
>>>> bind => [1, 1]
>>>> Query: DataModifyQuery(sql="INSERT INTO logical_endpoints_physical_endpoints (services_id, Endpoint_id) VALUES (?, ?)")
>>>> =========================_______________________________________________
>>>> eclipselink-users mailing list
>>>> eclipselink-users@xxxxxxxxxxx
>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>> ------------------------------------------------------------------------
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users