Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] NPE on update of inheritance table

Could you please include the exception and stack trace, and the SQL that is
generated.  Also the code that you are executing, and the mappings would be
helpful.

You may also wish to try the latest release to see if the issue still
occurs.



stryon wrote:
> 
> I have been working on an application that uses eclipselink 1.1.0.r3634.
> One of the things that I am trying to represent is a class hierarchy that
> is represented in the database as a group of tables. There is one table
> for the top level element that holds all of the common fields and
> sub-tables that hold all of the unique elements from the sub-classes. I
> have implemented this with entity classes that look something like this:
> 
> @Entity
> @Inheritance(strategy=javax.persistence.InheritanceType.JOINED)
> @DiscriminatorColumn(name="CAR_TYPE")
> @Table(name="CAR_DEFINITION")
> 
> @Entity
> @Table(name="SPORTS_CARS")
> @DiscriminatorValue(value="S")
> 
> @Entity
> @Table(name="VANS")
> @DiscriminatorValue(value="V")
> 
> This works most of the time but I ran into an odd issue  when trying to do
> an up update that just affected the fields in one of the sub-classes (ex.
> setCargoCapacity on a van). The issue was traced down to
> org.eclipse.persistence.internal.expressions.SQLModifiedStatement.buildCall(AbstractSession
> session). What was happening was while eclipselink was building up the sql
> string it would come down to this method to build the update string for
> the CAR_DEFINITION table. When it looked at the fields that needed to
> change, however, it saw that none of them were in the CAR_DEFINITION
> table.
> 
> Old Method:
> public DatabaseCall buildCal(AbstractSession session) {
>   SQLCall sqlCall = buildCallWithoutReturning(session);
>   if ((getReturnFields() == null) || (getReturnFields().isEmpty()) {
>     return sqlCall;
>   } else {
>     return
> session.getPlatform().buildCallWithoutReturning(sqlCall,getReturnFields());
>   }
> }
> 
> This would return a null from the first buildCallWithoutReturning. Since
> there were in fact fields that needed to be returned it would not
> immediately return. It would instead pass the null sqlCall variable into
> the platform's buildCallWithoutReturning method which then chokes on it
> with a Null Pointer Exception.
> 
> New Method:
> public DatabaseCall buildCal(AbstractSession session) {
>   SQLCall sqlCall = buildCallWithoutReturning(session);
>   // quickly return if the build call had nothing to build
>   if (sqlCall == null) || ((getReturnFields() == null) ||
> (getReturnFields().isEmpty()) {
>     return sqlCall;
>   } else {
>     return
> session.getPlatform().buildCallWithoutReturning(sqlCall,getReturnFields());
>   }
> }
> 
> The way that I tried to fix this was by simply checking the results
> returned from the first buildCallWithoutReturning call and returning
> immediately if it was null. This seems to work with all of the tests that
> I have run against it, but I am not familiar enough with eclipselink to
> know the ramifications of returning null from this method. Is this
> actually even an issue or am I doing something wrong with the
> configuration that is causing this problem? 
> 
> Also, is this something that has been previously detected and fixed? While
> it is one thing to override a classpath with a patched file, I would
> rather run with an official build.
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/NPE-on-update-of-inheritance-table-tp28560480p28599688.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top