• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Created blob cloumn for @OneToOne relation on gettermethod

 
Repala Madhu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,

Please see the following code. Here Alarm has a Severity with @OneToOne annotated on getter method severity field.
but it is created severity as TINYBLOB column in alarm table.

The table got created like this.
| severity | MOType | name | neName |


If i annotate with @OneToOne on severity field, then mappings like created.
This time table got created like this.
| MOType | name | neName | severity_MOType | severity_name | severity_neName |

Can anybody explain why it is creating BLOB column when annotating on getter method? how to resolve this?

Thanks in advance for all helps.

________________________________________________________________________________
import java.io.Serializable;

public class AppNameId implements Serializable{

protected String name;
protected String MOType;
/**
* @return the mOType
*/
public String getMOType() {
return MOType;
}
/**
* @param mOType the mOType to set
*/
public void setMOType(String mOType) {
MOType = mOType;
}
protected String neName;
/**
* @return the moName
*/
public String getName()
{
return name;
}
/**
* @param moName the moName to set
*/
public void setName(String name)
{
this.name = name;
}

/**
* @return the neName
*/
public String getNeName()
{
return neName;
}
/**
* @param neName the neName to set
*/
public void setNeName(String neName)
{
this.neName = neName;
}


}
______________________________________________________________________________________________________
import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
@Table(name = "NAME_")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Name
implements IName, Serializable
{
@Column(nullable = true, length = 252, insertable=false, updatable=false)
private String DTYPE;
@Id
protected String name;
@Id
protected String MOType;
@Id
protected String neName;
public Name()
{

}
public Name(String name, String moType, String neName)
{
this.name = name;
this.MOType = moType;
this.neName = neName;
}


public Name(IName iName) {
this.name = iName.getName();
this.MOType = iName.getMOType();
this.neName = iName.getNeName();
}
@Basic
@Column(name = "NAME_", length = 255)
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
@Basic
@Column(name = "MOTYPE", length = 255)
public String getMOType() {
return MOType;
}

public void setMOType(String value) {
this.MOType = value;
}
@Basic
@Column(name = "NENAME", length = 255)
public String getNeName() {
return neName;
}
public void setNeName(String value) {
this.neName = value;
}
public boolean equals(Object object)
{
boolean retVal = false;
IName aMO = (IName) object;
retVal = ( name.equals(aMO.getName()) &&
MOType.equals(aMO.getMOType()) &&
neName.equals(aMO.getNeName())
);
return retVal;
}

}
________________________________________________________________________________________________

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;

@Entity
@IdClass(AppNameId.class)
@Table(name = "APPMO")
@Inheritance(strategy = InheritanceType.JOINED)
public class AppMO implements IName{

@Id
private String name;
@Id
private String MOType;
@Id
private String neName;

public AppMO() {

}
public AppMO(String name, String MOType, String neName) {
this.name = name;
this.MOType = MOType;
this.neName = neName;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the mOType
*/
public String getMOType() {
return MOType;
}
/**
* @param mOType the mOType to set
*/
public void setMOType(String mOType) {
MOType = mOType;
}
/**
* @return the neName
*/
public String getNeName() {
return neName;
}
/**
* @param neName the neName to set
*/
public void setNeName(String neName) {
this.neName = neName;
}
}
___________________________________________________________________________________________



import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "severity")
public class Severity extends AppMO{
public Severity()
{

}

public Severity(String name, String mOType, String neName) {
super(name, mOType, neName);
}
}

_____________________________________________________________________________________


/**
* @copyright Teleparadigm Networks
* @author Paddy Vishnubhatt
* @date 03/14/2004
*/


import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
import javax.persistence.Table;
/**
* A managed object that encapsulates a Alarm.
*/
@Entity
@Table(name = "alarm")
public class Alarm extends AppMO
{
public Alarm()
{

}
public Alarm(String name, String mOType, String neName) {
super(name, mOType, neName);
}
private Severity severity;
/**
* @return the severity
*/
@OneToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH}, fetch = FetchType.EAGER)
public Severity getSeverity() {
return severity;
}
/**
* @param severity the severity to set
*/
public void setSeverity(Severity severity) {
this.severity = severity;
}
}
___________________________________________________________________________
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot annotate both fields and get method, you must choose only one, and be consistent in your class hierarchy.

Your issue is you annotated fields, but then put the OneToOne on the get method, so it is ignored.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic