gpt4 book ai didi

java - Hibernate:持续存在数据问题

转载 作者:行者123 更新时间:2023-12-01 11:11:59 25 4
gpt4 key购买 nike

无法让我的 setTestValue 方法将我的数据保留在数据库中,我正在从 readcsvfile 方法中调用此方法..我没有看到任何异常,但数据没有到达数据库..我正在使用 Hibernate 和 postgres db

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
@Service
public class TestValueService implements ITestValueService
{
/**
*
*/
private static final long serialVersionUID = -1027211428586214287L;

@Autowired
GenericDao genericDao;

private static final Logger LOG = Logger.getLogger(TestValueService.class);
private TestValue defaultValue;

public TestValueService()
{

}

@Transactional(readOnly = false)
**private void setTestValue**(TestValue defaultValue){
genericDao.makePersistent(defaultValue);
LOG.info("ballingss");
}
/*
* Method to read the defaults csv file and store into the common table
*/
@Override
//@Transactional(readOnly = false)
public void readCSVFile(String fileLocation, Long clientJobId){
String csvFile = fileLocation;
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";

try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {

// use comma as separator
String[] currentLine = line.split(cvsSplitBy);


TestValue defaultValue = new TestValue();
Date date = new Date();
defaultValue.setClient_job_id(clientJobId);
defaultValue.setCreate_dt(date);
defaultValue.setActive(true);
defaultValue.setDef_keyfield(currentLine[0].toUpperCase());
defaultValue.setDef_value(currentLine[1].toUpperCase());
**setTestValue(defaultValue);**

}

} catch (FileNotFoundException e) {
LOG.error("File Not found ");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}




}

这是表对象:

@Entity
@Table(name = "TEST_VALUE")
public class TestValue implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "default_values_def_id_seq")
@SequenceGenerator(name = "default_values_def_id_seq", sequenceName = "default_values_def_id_seq")
private Long def_id;

private Long client_job_id;

@Temporal(TemporalType.TIMESTAMP)
private Date create_dt;

@Basic
private String def_keyfield;

@Basic
private String def_value;

@Basic
boolean active = false;

public Long getDef_id()
{
return def_id;
}

public void setDef_id(Long def_id)
{
this.def_id = def_id;
}

public Long getClient_job_id()
{
return client_job_id;
}

public void setClient_job_id(Long client_job_id)
{
this.client_job_id = client_job_id;
}

public Date getCreate_dt()
{
return create_dt;
}

public void setCreate_dt(Date create_dt)
{
this.create_dt = create_dt;
}

public String getDef_keyfield()
{
return def_keyfield;
}

public void setDef_keyfield(String def_keyfield)
{
this.def_keyfield = def_keyfield;
}

public String getDef_value()
{
return def_value;
}

public void setDef_value(String def_value)
{
this.def_value = def_value;
}

public boolean isActive()
{
return active;
}

public void setActive(boolean active)
{
this.active = active;
}

public static long getSerialversionuid()
{
return serialVersionUID;
}



}

最佳答案

因为你没有任何异常,所以很难知道无法将数据保存到数据库的原因是什么。我想建议您可以执行一些步骤来检查代码:

Step1: Create an instance TestValue (don't read from your csv)
Step2: Test the save method in your GenericDAO <TestValue>

如果步骤2成功,我想你可以检查你的方法从你的csv数据加载。如果Step2不成功,请仔细检查GenericDao中的保存方法

如果您有异常(exception)情况,这将是我们跟踪问题并解决问题的信息。

希望这有帮助。

关于java - Hibernate:持续存在数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32239361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com