I'm doing the below query to find records that are in a temp table and dont exist in master then insert the results to the master table
#Query(value = "select b from InboundTemp b where b.transactionId NOT IN (SELECT p2.transactionId FROM Inbound p2)")
ArrayList<InboundTemp> findMissing();
However if I pass a single result object to the JpaRepository save method (To update the master table)it does an update instead of an insert.
what would I be doing wrong?
import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
#Entity
#Table(name="inbound_postpay_temp")
#NamedQuery(name="InboundPostpayTemp.findAll", query="SELECT i FROM InboundPostpayTemp i")
public class InboundPostpayTemp implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy= GenerationType.AUTO)
private int id;
#Column(name="bill_ref_no")
private String billRefNo;
#Column(name="business_shortcode")
private String businessShortcode;
private byte clicked;
#Temporal(TemporalType.TIMESTAMP)
#Column(name="created_at")
private Date createdAt;
private String kpresponse;
private String KPtransaction_id;
#Column(name="mpesa_sender")
private String mpesaSender;
private String msisdn;
#Column(name="Network")
private String network;
#Column(name="org_account_balance")
private float orgAccountBalance;
private String status;
#Column(name="transaction_amount")
private float transactionAmount;
#Column(name="transaction_id")
private String transactionId;
#Column(name="transaction_time")
private String transactionTime;
#Column(name="transaction_type")
private String transactionType;
#Temporal(TemporalType.TIMESTAMP)
#Column(name="updated_at")
private Date updatedAt;
public InboundPostpayTemp() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getBillRefNo() {
return this.billRefNo;
}
public void setBillRefNo(String billRefNo) {
this.billRefNo = billRefNo;
}
public String getBusinessShortcode() {
return this.businessShortcode;
}
public void setBusinessShortcode(String businessShortcode) {
this.businessShortcode = businessShortcode;
}
public byte getClicked() {
return this.clicked;
}
public void setClicked(byte clicked) {
this.clicked = clicked;
}
public Date getCreatedAt() {
return this.createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getKpresponse() {
return this.kpresponse;
}
public void setKpresponse(String kpresponse) {
this.kpresponse = kpresponse;
}
public String getKPtransaction_id() {
return this.KPtransaction_id;
}
public void setKPtransaction_id(String KPtransaction_id) {
this.KPtransaction_id = KPtransaction_id;
}
public String getMpesaSender() {
return this.mpesaSender;
}
public void setMpesaSender(String mpesaSender) {
this.mpesaSender = mpesaSender;
}
public String getMsisdn() {
return this.msisdn;
}
public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}
public String getNetwork() {
return this.network;
}
public void setNetwork(String network) {
this.network = network;
}
public float getOrgAccountBalance() {
return this.orgAccountBalance;
}
public void setOrgAccountBalance(float orgAccountBalance) {
this.orgAccountBalance = orgAccountBalance;
}
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public float getTransactionAmount() {
return this.transactionAmount;
}
public void setTransactionAmount(float transactionAmount) {
this.transactionAmount = transactionAmount;
}
public String getTransactionId() {
return this.transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public String getTransactionTime() {
return this.transactionTime;
}
public void setTransactionTime(String transactionTime) {
this.transactionTime = transactionTime;
}
public String getTransactionType() {
return this.transactionType;
}
public void setTransactionType(String transactionType) {
this.transactionType = transactionType;
}
public Date getUpdatedAt() {
return this.updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
}
The master class is the same
Below is the method that is persisting to dB
missing = temprepo.findMissing();
for (InboundPostpayTemp inboundPostpayTemp2 : missing) {
postpaytransaction.setBillRefNo(inboundPostpayTemp2.getBillRefNo());
postpaytransaction.setBusinessShortcode("");
// postpaytransaction.setClicked("0".t);
postpaytransaction
.setCreatedAt(new java.sql.Timestamp(inboundPostpayTemp2.getCreatedAt().getTime()));
postpaytransaction.setMpesaSender(inboundPostpayTemp2.getMpesaSender());
postpaytransaction.setMsisdn(inboundPostpayTemp2.getMsisdn());
postpaytransaction.setTransactionAmount(inboundPostpayTemp2.getTransactionAmount());
postpaytransaction.setTransactionId(inboundPostpayTemp2.getTransactionId());
postpaytransaction.setTransactionType("Paybill-Repost");
postpaytransaction.setStatus("CONFIRMED");
postpaytransaction.setTransactionTime(inboundPostpayTemp2.getTransactionTime());
//postpaytransactionx.add(postpaytransaction);
inboundpostpayrepo.save(postpaytransaction);
}
The only reason why JPA does an update instead of insert is that the Primary Key already exists in your persistence layer or your table. So kindly check or post your source code in order to review it and find what is wrong (if the issue is not in your data).
Now that you have updated the question with the source code, your bug is probably on the instantiation of the postpaytransaction object.
try to insert into your loop before everything else
postpaytransaction = new PostPayTransaction ()
I had the exactly same issue. My point was that the SpringBoot was automatically recreating the DB on startup, incorrectly creating the identity column in the table.
Look for spring.jpa.hibernate.ddl-auto.
Related
I have a field in the Firestore database that is TimeStamp and is in this format: Quarta-feira, 11 de Outubro de 2017 às 10:24:54 GMT-03:00
It is defined as: map.put("timestamp", FieldValue.serverTimestamp());
According to Firestore instructions, you need to add a annotation, directly to the model class.
I have in my class the TimeStamp field in String. I tried using TimeStamp and it does not work
What is the best way to solve this problem?
Code Class Model:
public class Servicos {
private String nome_produto;
private String duracao;
private String valor;
private String valor_old;
private String categoria;
private String categoria_nome;
private String sub_categoria;
private String sub_categoria_nome;
private String descricao;
private String duracao_milis;
private String timestamp;
public Servicos() {
}
public Servicos(String nome_produto, String duracao, String valor, String valor_old,
String categoria, String categoria_nome, String sub_categoria, String sub_categoria_nome,
String descricao, String duracao_milis, String timestamp){
this.nome_produto = nome_produto;
this.duracao = duracao;
this.valor = valor;
this.valor_old = valor_old;
this.categoria = categoria;
this.categoria_nome = categoria_nome;
this.duracao_milis = duracao_milis;
this.sub_categoria = sub_categoria;
this.sub_categoria_nome = sub_categoria_nome;
this.descricao = descricao;
this.timestamp = timestamp;
}
public String getNome_produto() {
return nome_produto;
}
public void setNome_produto(String nome_produto) {
this.nome_produto = nome_produto;
}
public String getDuracao() {
return duracao;
}
public void setDuracao(String duracao) {
this.duracao = duracao;
}
public String getValor() {
return valor;
}
public void setValor(String valor) {
this.valor = valor;
}
public String getValor_old() {
return valor_old;
}
public void setValor_old(String valor_old) {
this.valor_old = valor_old;
}
public String getCategoria() {
return categoria;
}
public void setCategoria(String categoria) {
this.categoria = categoria;
}
public String getCategoria_nome() {
return categoria_nome;
}
public void setCategoria_nome(String categoria_nome) {
this.categoria_nome = categoria_nome;
}
public String getSub_categoria() {
return sub_categoria;
}
public void setSub_categoria(String sub_categoria) {
this.sub_categoria = sub_categoria;
}
public String getSub_categoria_nome() {
return sub_categoria_nome;
}
public void setSub_categoria_nome(String sub_categoria_nome) {
this.sub_categoria_nome = sub_categoria_nome;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public String getDuracao_milis() {
return duracao_milis;
}
public void setDuracao_milis(String duracao_milis) {
this.duracao_milis = duracao_milis;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
}
Ref Firestore Documentation: Link Firestore
// If you're using custom Java objects in Android, add an #ServerTimestamp
// annotation to a Date field for your custom object classes. This indicates
// that the Date field should be treated as a server timestamp by the object mapper.
DocumentReference docRef = db.collection("objects").document("some-id");
// Update the timestamp field with the value from the server
Map<String,Object> updates = new HashMap<>();
updates.put("timestamp", FieldValue.serverTimestamp());
docRef.update(updates).addOnCompleteListener(new OnCompleteListener<Void>() {
// ...
// ...
Here's an example of how to use ServerTimestamp with a custom Java class:
public class Rating {
private String userId;
private #ServerTimestamp Date timestamp;
public Rating() {}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
}
Try this:
public class Klass {
private Date timestamp;
public Klass() {}
#ServerTimestamp
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
}
I need to map two pojo class using one to many, but getting the below error
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'testCaseStepsform' at row 1
When I saw the table created by hibernate, I found that a column with data type blob is created
I am adding the code below.
#Entity
#Table(name="TEST_CASE_DESC")
public class TestCaseForm implements Serializable{
/**
*
*/
private static final long serialVersionUID = 10001234L;
#Id
#Column(name="TEST_CASE_ID")
private String testCaseId;
#Column(name="PROJECT_NAME")
private String projectName;
#Column(name="PROJECT_ID")
private String projectId;
#Column(name="RELEASE_NAME")
private String releaseName;
#Column(name="RELEASE_ID")
private String releaseId;
#Column(name="ITERATION")
private String iteration;
#Column(name="TITLE")
private String title;
#Column(name="CREATED_BY")
private String createdBy;
#Column(name="CREATION_DATE")
private Date creationDate;
#Column(name="DESCRIPTION")
private String description;
#Column(name="PRE_CONDITION")
private String preCondition;
#Column(name="POST_CONDITION")
private String postCondition;
#Column(name="TYPE")
private String type;
#Column(name="IMPORTANCE")
private String importance;
private ArrayList<TestCaseStepsForm> testCaseStepsform = new ArrayList<TestCaseStepsForm>();
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPreCondition() {
return preCondition;
}
public void setPreCondition(String preCondition) {
this.preCondition = preCondition;
}
public String getPostCondition() {
return postCondition;
}
public void setPostCondition(String postCondition) {
this.postCondition = postCondition;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getRelease() {
return releaseName;
}
public void setReleaseName(String releaseName) {
this.releaseName = releaseName;
}
public String getReleaseId() {
return releaseId;
}
public void setReleaseId(String releaseId) {
this.releaseId = releaseId;
}
public String getIteration() {
return iteration;
}
public void setIteration(String iteration) {
this.iteration = iteration;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getReleaseName() {
return releaseName;
}
public String getImportance() {
return importance;
}
public void setImportance(String importance) {
this.importance = importance;
}
#OneToMany(mappedBy = "TEST_CASE_DESC", cascade = CascadeType.ALL)
public ArrayList<TestCaseStepsForm> getTestCaseStepsform() {
return testCaseStepsform;
}
public void setTestCaseStepsform(ArrayList<TestCaseStepsForm> testCaseStepsform) {
this.testCaseStepsform = testCaseStepsform;
}
public String getTestCaseId() {
return testCaseId;
}
public void setTestCaseId(String testCaseId) {
this.testCaseId = testCaseId;
}
}
#Entity
#Table(name="TEST_CASE_STEP")
public class TestCaseStepsForm implements Serializable{
/**
*
*/
private static final long serialVersionUID = 123456788091L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(name="SERIAL_NUMBER")
private String serialNumber;
#Column(name="TEST_CASE_ID")
private String testCaseId;
#Column(name="INPUT")
private String input;
#Column(name="EXPCETED_OUTPUT")
private String expectedOutput;
#Column(name="STATUS")
private String status;
private TestCaseForm testCaseForm;
public String getTestCaseId() {
return testCaseId;
}
public void setTestCaseId(String testCaseId) {
this.testCaseId = testCaseId;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getExpectedOutput() {
return expectedOutput;
}
public void setExpectedOutput(String expectedOutput) {
this.expectedOutput = expectedOutput;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
#ManyToOne( fetch = FetchType.LAZY)
#JoinColumn(name = "TEST_CASE_ID", nullable = false)
public TestCaseForm getTestCaseForm() {
return testCaseForm;
}
public void setTestCaseForm(TestCaseForm testCaseForm) {
this.testCaseForm = testCaseForm;
}
public String getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
}
#Configuration
public class TestCaseConfig {
#Bean(name="testCaseForm1")
public TestCaseForm testCaseForm1(){
TestCaseForm tst = new TestCaseForm();
tst.setTestCaseId("1122233");
tst.setProjectId("1234");
tst.setReleaseName("June");
tst.setReleaseId("1707");
tst.setIteration("2");
tst.setProjectName("ExpressPay");
tst.setTitle("ExpressPay");
tst.setCreatedBy("Anirban Deb");
tst.setCreationDate(new Date());
tst.setDescription("ExpressPay Login");
tst.setPreCondition("Active account");
tst.setPostCondition("success");
TestCaseStepsForm str1 = new TestCaseStepsForm();
str1.setTestCaseId("1122233");
str1.setInput("Hello World");
str1.setExpectedOutput("Bye Bye world");
str1.setStatus("Run");
str1.setTestCaseForm(tst);
TestCaseStepsForm str2 = new TestCaseStepsForm();
str2.setTestCaseId("1122233");
str2.setInput("Hello World");
str2.setExpectedOutput("Bye Bye world");
str2.setStatus("Run");
str1.setTestCaseForm(tst);
tst.getTestCaseStepsform().add(str1);
tst.getTestCaseStepsform().add(str2);
return tst;
}
}
public class Main {
public static void main(String[] args) throws MessagingException {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("core-bean.xml");
TestCaseForm test1 = context.getBean("testCaseForm1",TestCaseForm.class);
ITestCaseService testCase = context.getBean("testCaseServiceImp", ITestCaseService.class);
testCase.inserTestCase(test1);
[enter image description here][1]
stopWatch.stop();
System.out.println("Time taken in execution : "+stopWatch.getTotalTimeSeconds());
}
}
You should choose to annotate object properties or getters. Don't use it simultaneously.
Apart, #xl0e answer
You need to correct mapping
#OneToMany(mappedBy = "testCaseForm", cascade = CascadeType.ALL)
public ArrayList<TestCaseStepsForm> getTestCaseStepsform() {
return testCaseStepsform;
}
Helo,
I have method
public void createContest(Contest c) {
session.beginTransaction();
session.persist(c);
session.getTransaction().commit();
logger.info("Contest saved successfully!");
}
I call it in one place with one object but this method save the object Contest to the database 4x. What could be the problem?
Here is Contest class:
#Entity
#Table(name = "Contest")
public class Contest implements java.io.Serializable {
#Id
#Column(name="CONTEST_ID", unique = true, nullable = false, precision = 5, scale = 0)
#GeneratedValue
private int id;
#Column(name="NAME")
private String name;
#Column(name="DATE_OF_EVENT")
private Date dateOfEvent;
#Column(name="REG_OPEN")
private Date regOpen;
#Column(name="REG_CLOSE")
private Date regClose;
#Column(name="REG_RESTRICTION")
private Boolean regRestriction;
#Column(name="CAPACITY")
private int capacity;
#OneToMany(mappedBy="upperContest")
private List<Contest> precontests;
#ManyToOne(cascade={CascadeType.ALL})
#JoinColumn(name="UPPER_CONTEST_ID")
private Contest upperContest;
#ManyToMany(cascade = {CascadeType.ALL})
#JoinTable(name="MANAGING",
joinColumns={#JoinColumn(name="CONTEST_ID")},
inverseJoinColumns={#JoinColumn(name="PERSON_ID")})
private List<Person> managers;
#OneToMany(mappedBy="contest")
private List<Team> teams;
public Contest(String name, Date dateOfEvent, Date regOpen,
Date regClose, Boolean regRestriction) {
this.name = name;
this.dateOfEvent = dateOfEvent;
this.regOpen = regOpen;
this.regClose = regClose;
this.regRestriction = regRestriction;
this.precontests = new ArrayList<Contest>();
this.managers = new ArrayList<Person>();
this.teams = new ArrayList<Team>();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDateOfEvent() {
return dateOfEvent;
}
public void setDateOfEvent(Date dateOfEvent) {
this.dateOfEvent = dateOfEvent;
}
public Date getRegOpen() {
return regOpen;
}
public void setRegOpen(Date regOpen) {
this.regOpen = regOpen;
}
public Date getRegClose() {
return regClose;
}
public void setRegClose(Date regClose) {
this.regClose = regClose;
}
public Boolean getRegRestriction() {
return regRestriction;
}
public void setRegRestriction(Boolean regRestriction) {
this.regRestriction = regRestriction;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public Contest getUpperContest() {
return upperContest;
}
public void setUpperContest(Contest c) {
this.upperContest = c;
}
public List<Contest> getPrecontests() {
return precontests;
}
public void addPrecontest(Contest e) {
this.precontests.add(e);
}
public void addManager(Person p){
this.managers.add(p);
}
public void addTeam(Team t){
this.teams.add(t);
}
public List<Person> getManagers(){
return managers;
}
}
And now I have to add some text because of restrictions of stackoverflow. Such Cool. Very wow.
You haven't posted the code where you instantiate Contest and populate its fields, but upperContest is probably the cause. You have CascadeType.ALL on the mapping, so you probably are persisting one contest which has a upper contest, thus actually persisting two instances because of cascade setting. Can't know for sure without that code.
I have a Hibernate persist on an entity with primary key constructor, but it does not take effect in the database after something I don't know while I need it in some other methods
Here is my code:
Base_Document document = new Base_Document(workItem.getProcessInstanceId());
this.getEntityManager().persist(document);
this.getEntityManager().flush();
this.getEntityManager().close();
and some where else I have :
Object o = this.getEntityManager().find(Base_Document.class,
workItem.getProcessInstanceId());
where o is null. Any help?
my entity code :
#Entity
public class Base_Document implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private Long processInstanceId;
private DocumentStatus status;
#ManyToOne
private Base_Roles creatorRole;
#Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date createDate;
public Base_Document() {}
public Base_Document(Long processInstanceId) {
this.processInstanceId = processInstanceId;
this.createDate = new Date();
this.status = DocumentStatus.DRAFT;
try {
String currentUser = PublicUtils.getHttpServletRequest().getUserPrincipal().getName();
this.setCreatorRole(PublicUtils.getEntityManager().find(Base_Roles.class, currentUser));
} catch (PolicyContextException ex) {
Logger.getLogger(Base_Document.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Long getId() {
return processInstanceId;
}
public void setId(Long id) {
this.processInstanceId = id;
}
public Long getProcessInstanceId() {
return processInstanceId;
}
public void setProcessInstanceId(Long processInstanceId) {
this.processInstanceId = processInstanceId;
}
public DocumentStatus getStatus() {
return status;
}
public void setStatus(DocumentStatus status) {
this.status = status;
}
public Base_Roles getCreatorRole() {
return creatorRole;
}
public void setCreatorRole(Base_Roles creatorRole) {
this.creatorRole = creatorRole;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
From Hibernate "persist" description:
However, it does not guarantee that the identifier value will be assigned to the persistent instance immediately
https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Web_Platform/5/html/Hibernate_Core_Reference_Guide/objectstate-makingpersistent.html
You can use "save()" if immediately search required.
I have stored images in image data type in binary format in MSSQL.Now I have migrated my database from MSSQL to Postgres 9.0 and trying to store image files in bytea field.When I am trying to convert these bytes into image file though I am not getting any error but Image is not getting rendered where as the same java code is working fine with MSSQL.My application is struts hibernate based application.My hibernate dto is like following-
#Entity
#Table(name="Image_Type")
public class ImageType extends AbstractPO
{
private static final long serialVersionUID = 1L;
private Long id;
private Long ownerId;
private Short ownerType;
private String name;
private String description;
private Long typeId;
private byte[] originalImage;
private byte[] thumbNailImage;
private byte[] terminalImage;
private String createdBy;
private Date createdOn;
private String modifiedBy;
private Date modifiedOn;
private String rfu1;
private String rfu2;
private String rfu3;
#Id #GeneratedValue(strategy=AUTO, generator="Image_Type_seq")
#SequenceGenerator(name="Image_Type_seq", sequenceName="IMAGE_TYPE_IMAGE_TYPEID_SEQ")
#Column(name="Image_TypeID", unique=true, nullable=false, precision=10, scale=0)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
#Column(name="OwnerID", precision=10, scale=0)
public Long getOwnerId() {
return this.ownerId;
}
public void setOwnerId(Long ownerId) {
this.ownerId = ownerId;
}
#Column(name="OwnerType", precision=4, scale=0)
public Short getOwnerType() {
return this.ownerType;
}
public void setOwnerType(Short ownerType) {
this.ownerType = ownerType;
}
#Column(name="Name", length=100)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
#Column(name="Description", length=100)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
#Column(name="TypeID", precision=10, scale=0)
public Long getTypeId() {
return this.typeId;
}
public void setTypeId(Long typeId) {
this.typeId = typeId;
}
#Column(name="Original_Image")
public byte[] getOriginalImage() {
return this.originalImage;
}
public void setOriginalImage(byte[] originalImage) {
this.originalImage = originalImage;
}
#Column(name="ThumbNail_Image")
public byte[] getThumbNailImage() {
return this.thumbNailImage;
}
public void setThumbNailImage(byte[] thumbNailImage) {
this.thumbNailImage = thumbNailImage;
}
#Column(name="Terminal_Image")
public byte[] getTerminalImage() {
return this.terminalImage;
}
public void setTerminalImage(byte[] terminalImage) {
this.terminalImage = terminalImage;
}
#Column(name="CreatedBy", length=50)
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
#Column(name="CreatedOn", nullable=false, length=23)
public Date getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
#Column(name="ModifiedBy", length=50)
public String getModifiedBy() {
return this.modifiedBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
#Column(name="ModifiedOn", length=23)
public Date getModifiedOn() {
return this.modifiedOn;
}
public void setModifiedOn(Date modifiedOn) {
this.modifiedOn = modifiedOn;
}
#Column(name="RFU1", length=100)
public String getRfu1() {
return this.rfu1;
}
public void setRfu1(String rfu1) {
this.rfu1 = rfu1;
}
#Column(name="RFU2", length=100)
public String getRfu2() {
return this.rfu2;
}
public void setRfu2(String rfu2) {
this.rfu2 = rfu2;
}
#Column(name="RFU3", length=100)
public String getRfu3() {
return this.rfu3;
}
public void setRfu3(String rfu3) {
this.rfu3 = rfu3;
}
}
Kindly help me to resolve this issue
Which version of Postgresql are you using? Are you using server version 9 and JDBC driver 8.4? (because if so: Hibernate 3.3.2GA improperly loads bytea data from PostgreSQL 9.0 and all type mappings are correct)
What is the actual value being stored in the database? Use psql to check, and compare the first 16 bytes or so with the expected values. Since they are images you would expect them to start with some format magic- "JFIF", "GIF", "PNG", "II"/"MM" etc. You need to be able to determine if the data is being corrupted when being saved, corrupted when being loaded or some other problem. Dump the first few bytes of the image array before saving the object and after loading to compare with the values from psql.