-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: TABLE_PER_CLASS causes a NPE, whereas JOINED and ST works
PostPosted: Tue Jun 19, 2007 7:51 am 
Newbie

Joined: Tue Jun 19, 2007 7:25 am
Posts: 7
Hi,

I have a scenario, where an inheritance-strategy using SINGLE_TABLE or JOINED perfectly works, but TABLE_PER_CLASS throws a NullPointerException.

I wonder if this is meant to be this way or if I have an error somewhere.
This is my class-structure:

I have a Entity called ClearingItem that has a reference to a discount-entity. This discount-entity might be either one object inheriting DiscountBase or one object inheriting FullDiscount. The FullDiscount-Objects always have an aggregation to one DiscountBase-Object. Every time I try to access the DiscountBase in one of the FullDiscount-Objects I get a NPE, because the reference has not been loaded. The funny thing is, it is either one way or another - that means either the FixedDiscount-tree works or fails or the PercentagedDiscount-tree works or fails, but it´s never mixed.

I attached an excerpt of my classes, but I reduced it to the necessary getters and the class-annotations

## Class BaseEntity
@MappedSuperclass
public abstract class BaseEntit {

protected long id = 0;
protected long version = 0L;

@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
public long getId(){
return id;
}

...
}


## Class Discount
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class Discount extends BaseEntity implements Discountable { ...
}

## Class DiscountBase
@Entity
public abstract class DiscountBase extends Discount {
...
}

## Class FullDiscount
@Entity
public abstract class FullDiscount extends Discount {
...
}

## Class FixedDiscountBase
@Entity
@Table(name="fixed_discount_base")
public class FixedDiscountBase extends DiscountBase implements IFixedDiscount {
}

## Class PercentagedDiscountBase
@Entity
@Table(name="percentaged_discount_base")
public class PercentagedDiscountBase extends DiscountBase implements IPercentagedDiscount {
}

## Class FixedDiscount
@Entity
@Table(name="fixed_discount")
public class FixedDiscount extends Discount {

private FixedDiscountBase base = null;

@ManyToOne
@JoinColumn
public FixedDiscountBase getFixedDiscountBase() {
return base;
}
}

## Class PercentagedDiscount
@Entity
@Table(name="percentaged_discount")
public class PercentagedDiscount extends Discount {

private PercentagedDiscountBase base = null;

@ManyToOne
@JoinColumn
public PercentagedDiscountBase getPercentagedDiscountBase() {
return base;
}
}

##Class ClearingItem
@Entity
public class ClearingItem extends BaseEntity{

private Discount discount = null;

@ManyToOne(cascade = { CascadeType.ALL }, fetch=FetchType.EAGER)
@JoinColumn(nullable=false)
public Discount getDiscount() {
return discount;
}

}


Hibernate version:
3.2.2GA
3.3.0GA for Hibernate-Annotations

Stacktrace:
java.lang.NullPointerException
at FixedDiscount.<init>(FixedDiscount.java:40)
at ClearingItem.<init>(ClearingItem.java:131)
at testPersist(ManualBillingClearingItemPersistenceTests.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:604)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:470)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:830)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:678)
at org.testng.TestRunner.privateRun(TestRunner.java:624)
at org.testng.TestRunner.run(TestRunner.java:495)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
at org.testng.SuiteRunner.run(SuiteRunner.java:190)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
at org.testng.TestNG.run(TestNG.java:699)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)


Name and version of the database you are using:
HsqlDB 1.8.0.7


So If anyone has an idea, what causes this problem, I´d be glad if you´d let me know.

Thanks
Thomas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.