• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HibernateTools Generating Wrong Code

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to generate java classes using hibernate tools for ejb3

I am running ant on the build.xml attached.
I have the following issues,
[1] the java generated classes have wrong schema name, I would prefer no schema name or at best the correct one
[2] the oracle sequence is wrong for the id, instead it generates a composite id for reasons unclear to me,
the sequence generated should look something like this:
[3] its generating the Account class and AccountId class where as I want just one class,

if I can't get this script to work I will just have to delete hibernateTools and the script and code it manually, but since I have 50+ tables that would be a pain

[code]@ Entity ( )
@ Table ( name = "ACCOUNT" )

public class Account implements Serializable
{
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L ;
@ Id ( )
@ SequenceGenerator ( name = "AccountIdGenerator" , sequenceName = "SEQ_ACCOUNT" )
@ GeneratedValue ( strategy = GenerationType.SEQUENCE , generator = "AccountIdGenerator" )
@ Column ( name = "ID" )
private Long id ;[/code]

instead the output class looks like this:

//----------------------------------------------------------------------------------------
[code]package java.ejb.jpa;
// Generated Mar 2, 2010 4:55:40 PM by Hibernate Tools 3.2.2.GA


import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
* Account generated by hbm2java
*/
@Entity
@Table(name="ACCOUNT"
,schema="BUFFALO"
)
public class Account implements java.io.Serializable {


private AccountId id;

public Account() {
}

public Account(AccountId id) {
this.id = id;
}

@EmbeddedId

@AttributeOverrides( {
@AttributeOverride(name="dateCreated", column=@Column(name="DATE_CREATED", length=7) ),
@AttributeOverride(name="dateModified", column=@Column(name="DATE_MODIFIED", length=7) ),
@AttributeOverride(name="modifiedBy", column=@Column(name="MODIFIED_BY", length=50) ),
@AttributeOverride(name="createdBy", column=@Column(name="CREATED_BY", length=50) ),
@AttributeOverride(name="spa", column=@Column(name="SPA", length=50) ),
@AttributeOverride(name="serviceAddressId", column=@Column(name="SERVICE_ADDRESS_ID", precision=38, scale=0) ),
@AttributeOverride(name="accountType", column=@Column(name="ACCOUNT_TYPE", length=50) ),
@AttributeOverride(name="accountStatus", column=@Column(name="ACCOUNT_STATUS", length=25) ),
@AttributeOverride(name="id", column=@Column(name="ID", precision=38, scale=0) ),
@AttributeOverride(name="customerId", column=@Column(name="CUSTOMER_ID", precision=38, scale=0) ),
@AttributeOverride(name="regCode", column=@Column(name="REG_CODE", length=25) ),
@AttributeOverride(name="billingAddressId", column=@Column(name="BILLING_ADDRESS_ID", precision=38, scale=0) ) } )
public AccountId getId() {
return this.id;
}

public void setId(AccountId id) {
this.id = id;
}




}
[/code]
//----------------------------------------------------------------------------------------

[code]package java.ejb.jpa;
// Generated Mar 2, 2010 4:55:40 PM by Hibernate Tools 3.2.2.GA


import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
* AccountId generated by hbm2java
*/
@Embeddable
public class AccountId implements java.io.Serializable {


private Date dateCreated;
private Date dateModified;
private String modifiedBy;
private String createdBy;
private String spa;
private long serviceAddressId;
private String accountType;
private String accountStatus;
private long id;
private long customerId;
private String regCode;
private long billingAddressId;

public AccountId() {
}

public AccountId(Date dateCreated, Date dateModified, String modifiedBy, String createdBy, String spa, long serviceAddressId, String accountType, String accountStatus, long id, long customerId, String regCode, long billingAddressId) {
this.dateCreated = dateCreated;
this.dateModified = dateModified;
this.modifiedBy = modifiedBy;
this.createdBy = createdBy;
this.spa = spa;
this.serviceAddressId = serviceAddressId;
this.accountType = accountType;
this.accountStatus = accountStatus;
this.id = id;
this.customerId = customerId;
this.regCode = regCode;
this.billingAddressId = billingAddressId;
}


@Column(name="DATE_CREATED", length=7)
public Date getDateCreated() {
return this.dateCreated;
}

public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}

@Column(name="DATE_MODIFIED", length=7)
public Date getDateModified() {
return this.dateModified;
}

public void setDateModified(Date dateModified) {
this.dateModified = dateModified;
}

@Column(name="MODIFIED_BY", length=50)
public String getModifiedBy() {
return this.modifiedBy;
}

public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}

@Column(name="CREATED_BY", length=50)
public String getCreatedBy() {
return this.createdBy;
}

public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}

@Column(name="SPA", length=50)
public String getSpa() {
return this.spa;
}

public void setSpa(String spa) {
this.spa = spa;
}

@Column(name="SERVICE_ADDRESS_ID", precision=38, scale=0)
public long getServiceAddressId() {
return this.serviceAddressId;
}

public void setServiceAddressId(long serviceAddressId) {
this.serviceAddressId = serviceAddressId;
}

@Column(name="ACCOUNT_TYPE", length=50)
public String getAccountType() {
return this.accountType;
}

public void setAccountType(String accountType) {
this.accountType = accountType;
}

@Column(name="ACCOUNT_STATUS", length=25)
public String getAccountStatus() {
return this.accountStatus;
}

public void setAccountStatus(String accountStatus) {
this.accountStatus = accountStatus;
}

@Column(name="ID", precision=38, scale=0)
public long getId() {
return this.id;
}

public void setId(long id) {
this.id = id;
}

@Column(name="CUSTOMER_ID", precision=38, scale=0)
public long getCustomerId() {
return this.customerId;
}

public void setCustomerId(long customerId) {
this.customerId = customerId;
}

@Column(name="REG_CODE", length=25)
public String getRegCode() {
return this.regCode;
}

public void setRegCode(String regCode) {
this.regCode = regCode;
}

@Column(name="BILLING_ADDRESS_ID", precision=38, scale=0)
public long getBillingAddressId() {
return this.billingAddressId;
}

public void setBillingAddressId(long billingAddressId) {
this.billingAddressId = billingAddressId;
}


public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof AccountId) ) return false;
AccountId castOther = ( AccountId ) other;

return ( (this.getDateCreated()==castOther.getDateCreated()) || ( this.getDateCreated()!=null && castOther.getDateCreated()!=null && this.getDateCreated().equals(castOther.getDateCreated()) ) )
&& ( (this.getDateModified()==castOther.getDateModified()) || ( this.getDateModified()!=null && castOther.getDateModified()!=null && this.getDateModified().equals(castOther.getDateModified()) ) )
&& ( (this.getModifiedBy()==castOther.getModifiedBy()) || ( this.getModifiedBy()!=null && castOther.getModifiedBy()!=null && this.getModifiedBy().equals(castOther.getModifiedBy()) ) )
&& ( (this.getCreatedBy()==castOther.getCreatedBy()) || ( this.getCreatedBy()!=null && castOther.getCreatedBy()!=null && this.getCreatedBy().equals(castOther.getCreatedBy()) ) )
&& ( (this.getSpa()==castOther.getSpa()) || ( this.getSpa()!=null && castOther.getSpa()!=null && this.getSpa().equals(castOther.getSpa()) ) )
&& (this.getServiceAddressId()==castOther.getServiceAddressId())
&& ( (this.getAccountType()==castOther.getAccountType()) || ( this.getAccountType()!=null && castOther.getAccountType()!=null && this.getAccountType().equals(castOther.getAccountType()) ) )
&& ( (this.getAccountStatus()==castOther.getAccountStatus()) || ( this.getAccountStatus()!=null && castOther.getAccountStatus()!=null && this.getAccountStatus().equals(castOther.getAccountStatus()) ) )
&& (this.getId()==castOther.getId())
&& (this.getCustomerId()==castOther.getCustomerId())
&& ( (this.getRegCode()==castOther.getRegCode()) || ( this.getRegCode()!=null && castOther.getRegCode()!=null && this.getRegCode().equals(castOther.getRegCode()) ) )
&& (this.getBillingAddressId()==castOther.getBillingAddressId());
}

public int hashCode() {
int result = 17;

result = 37 * result + ( getDateCreated() == null ? 0 : this.getDateCreated().hashCode() );
result = 37 * result + ( getDateModified() == null ? 0 : this.getDateModified().hashCode() );
result = 37 * result + ( getModifiedBy() == null ? 0 : this.getModifiedBy().hashCode() );
result = 37 * result + ( getCreatedBy() == null ? 0 : this.getCreatedBy().hashCode() );
result = 37 * result + ( getSpa() == null ? 0 : this.getSpa().hashCode() );
result = 37 * result + (int) this.getServiceAddressId();
result = 37 * result + ( getAccountType() == null ? 0 : this.getAccountType().hashCode() );
result = 37 * result + ( getAccountStatus() == null ? 0 : this.getAccountStatus().hashCode() );
result = 37 * result + (int) this.getId();
result = 37 * result + (int) this.getCustomerId();
result = 37 * result + ( getRegCode() == null ? 0 : this.getRegCode().hashCode() );
result = 37 * result + (int) this.getBillingAddressId();
return result;
}


}
[/code]


//----------------------------------------------------------------------------------------
// here is persistence.xml
[code]<?xml version="1.0" encoding="UTF-8"?>

<persistence 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"
version="1.0">

<persistence-unit name="myJPA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.username" value="BUFFALO" />
<property name="hibernate.connection.password" value="asdf1234" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:asdf1234" />
</properties>
</persistence-unit>

</persistence>[/code]
//----------------------------------------------------------------------------------------
[code]// here is build.xml
<project name = "generate_jpa" default = "all">
<path id = "classpath">
<fileset dir = "lib" includes = "**/*.jar"/>
</path>
<taskdef name = "hibernatetool" classname = "org.hibernate.tool.ant.HibernateToolTask" classpathref = "classpath"/>
<target name = "all">
<delete dir="./output" />
<mkdir dir="./output" />
<hibernatetool destdir = "./output">
<jpaconfiguration persistenceunit = "myJPA" propertyfile="hibernate.properties" />
<hbm2cfgxml ejb3="true" />
<classpath>
<path location = "."/>
<path>
<fileset dir = "lib" includes = "**/*.jar"/>
</path>
</classpath>
</hibernatetool>
<hibernatetool destdir = "./output">
<jdbcconfiguration propertyfile="hibernate.properties"
revengfile="./reveng.xml"
packagename="java.ejb.jpa" />
<hbm2hbmxml destdir="./output" />
<hbm2java destdir="./output" jdk5 = "true" ejb3 = "true" />
</hibernatetool>

</target>
</project>[/code]

//----------------------------------------------------------------------------------------
// here is reveng.xml
[code]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="NUMERIC" hibernate-type="long" />
<sql-type jdbc-type="INTEGER" hibernate-type="long" />
</type-mapping>
<!-- BIN$ is recycle bin tables in Oracle -->
<table-filter match-name="ACCOUNT" exclude="false" />
<table-filter match-name="BIN$.*" exclude="true" />
<table-filter match-name="SYS.$.*" exclude="true" />
<table-filter match-name="*$*" exclude="true" />
<table-filter match-name="SYS*" exclude="true" />
<table-filter match-name="*SYS*" exclude="true" />
<table schema="asdf1234" name="ACCOUNT" class="Account">
<primary-key>
<generator class="GenerationType.SEQUENCE">
<param name="sequence">SEQ_ACCOUNT</param>
</generator>
<key-column name="ID" />
</primary-key>
</table>

</hibernate-reverse-engineering>[/code]
//----------------------------------------------------------------------------------------
[code]// here is hibernate.properties
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.connection.driver_class=oracle.jdbc.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@127.0.0.1:1521:asdf1234
hibernate.connection.username=BUFFALO
hibernate.connection.password=asdf1234
hibernate.hbm2ddl.auto=update
hibernate.default.schema=asdf1234
hibernate.statement_cache.size=0
hibernate.jdbc.batch_size=0
hibernate.dbcp.ps.maxIdle = 0
hibernate.jdbc.wrap_result_sets=true[/code]

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
 
Johnny SmithyJr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added a missing primary key flag on id to get rid of most of my issues, the only one left is that is keeps generating sequence type of assigned instead of sequence, I have tried both methods below and it doesnt generate the sequence





 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic