Announcement Announcement Module
Collapse
No announcement yet.
Spring JPA Project -- Creating entities from table using Hibernate and sybase Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JPA Project -- Creating entities from table using Hibernate and sybase

    Hi,

    I am trying to generate JPA entities from existing tables using JPA tools provided in the SpringSource 3.1. For this I have created one JPA project. The setup is

    Hibernate version 4.1.4
    Sybase ASE 15.7

    The problem is, when I try to create entity for the table below :

    Code:
    create table validation_error  (
            job_id   bigint not null,
            line_number bigint not null,
    	test_it     bigint ,
            description      varchar(132),
     	primary key clustered (job_id,line_number)
    )
    It maps to two entities as it has composite primary key.
    Code:
    @Entity
    @Table(name="validation_error")
    public class ValidationError implements Serializable, DomainObject {
    	private static final long serialVersionUID = 1L;
    	private ValidationErrorPK id;
    	private String description;
    	private BigInteger testIt;
    
    	public ValidationError() {
    	}
    
    
    	@EmbeddedId
    	public ValidationErrorPK getId() {
    		return this.id;
    	}
    
    	public void setId(ValidationErrorPK id) {
    		this.id = id;
    	}
    
    
    	@Column(nullable=false, length=132)
    	public String getDescription() {
    		return this.description;
    	}
    
    	public void setDescription(String description) {
    		this.description = description;
    	}
    
    
    	@Column(name="test_it", nullable=false)
    	public BigInteger getTestIt() {
    		return this.testIt;
    	}
    
    	public void setTestIt(BigInteger testIt) {
    		this.testIt = testIt;
    	}
    
    }
    and
    Code:
    @Embeddable
    public class ValidationErrorPK implements Serializable {
    	//default serial version id, required for serializable classes.
    	private static final long serialVersionUID = 1L;
    	private String jobId;
    	private String lineNumber;
    
    	public ValidationErrorPK() {
    	}
    
    	@Column(name="job_id", unique=true, nullable=false)
    	public String getJobId() {
    		return this.jobId;
    	}
    	public void setJobId(String jobId) {
    		this.jobId = jobId;
    	}
    
    	@Column(name="line_number", unique=true, nullable=false)
    	public String getLineNumber() {
    		return this.lineNumber;
    	}
    	public void setLineNumber(String lineNumber) {
    		this.lineNumber = lineNumber;
    	}
    
    	public boolean equals(Object other) {
    		if (this == other) {
    			return true;
    		}
    		if (!(other instanceof ValidationErrorPK)) {
    			return false;
    		}
    		ValidationErrorPK castOther = (ValidationErrorPK)other;
    		return 
    			this.jobId.equals(castOther.jobId)
    			&& this.lineNumber.equals(castOther.lineNumber);
    	}
    
    	public int hashCode() {
    		final int prime = 31;
    		int hash = 17;
    		hash = hash * prime + this.jobId.hashCode();
    		hash = hash * prime + this.lineNumber.hashCode();
    		
    		return hash;
    	}
    }
    From the code it shows that the bigint columns in the primary key are mapped to String instead of BigInteger but the non-key test_it field is mapped to proper BigInteger.

    Any Specific reason of this type of different conversion ? and is any addition setting is required to correct this problem ?

    Thanks
Working...
X