Hi guys,
I'm trying to generate ddl from my annotated pojos, and somewhere I've got the mapping-annotations wrong (I assume), but instead of getting a nice message telling me that something doesn't make sense I'm getting a NullPointerException from somewhere in the hibernate stack. Any help would be appreciated.
I'm using the hib tools from a maven plug-in embedded in Idea, but I get the same problem in Ant, so it doesn't appear to be a maven or Idea problem.
The stack-trace starts like this:
java.lang.NullPointerException
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:382)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
at org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfiguration.getConfiguration(AbstractComponentConfiguration.java:38)
at org.codehaus.mojo.hibernate3.exporter.Hbm2DDLExporterMojo.doExecute(Hbm2DDLExporterMojo.java:87)
at org.codehaus.mojo.hibernate3.HibernateExporterMojo.execute(HibernateExporterMojo.java:139)
and then degenerates into more environment specific stuff:
My dependencies (cut from my POM) are:
<artifactId>hibernate</artifactId>
<version>3.2.4.sp1</version>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.ga</version>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0.beta9a</version>
My annotated pojos look a bit like this:
@Entity
public class Security {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
long id;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private SecurityIdentifier identifier;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Country country;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Currency currency;
private BigDecimal issuePrice;
@Temporal(TemporalType.DATE)
private Date dated;
@Temporal(TemporalType.DATE)
private Date firstCouponDate;
private Long couponRefixFreq;
@Temporal(TemporalType.DATE)
private Date nextRefixDate;
etc...
}
@Entity
public class SecurityIdentifier extends StaticData {
etc.
}
@MappedSuperclass
public abstract class StaticData {
@Id
private int code;
}
All of the n:1 relationships are to StaticData implementations.
The ant script (again, from my POM), is:
<tasks>
<echo message="Generating DDL (from maven)..."/>
<property name="dir.config" location="src/main/config"/>
<property file="${dir.config}/db.properties"/>
<property name="file.hibernate.cfg" value="${dir.config}/hibernate.cfg.xml"/>
<echo message="Using hibernate cfg: ${file.hibernate.config}"/>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="maven.test.classpath"/>
<hibernatetool destdir="src/main/sql">
<classpath>
<path location="target/classes"/>
</classpath>
<annotationconfiguration configurationfile="src/main/config//hibernate.cfg.xml"/>
<hbm2ddl export="false" drop="true" create="true" console="false"
outputfilename="schema.sql" format="true" haltonerror="true"
delimiter=";"/>
</hibernatetool>
</tasks>
The first couple of lines from my database.properties file are:
hibernate.dialect=org.hibernate.dialect.SybaseDialect
driver.class=com.sybase.jdbc3.jdbc.SybDrive
my hibernate.cfg.xml contains similar information (identical, except that it's xml).
TIA:
Bryan
|