CrudRepository保存方法未保存到oracle数据库

来源:爱站网时间:2021-09-16编辑:网友分享
我正在尝试创建一个应用程序,以使用CrudRepository将数据保存到Oracle数据库中。这是我的存储库:公用接口CustomerRepository扩展了CrudRepository ...] >>

问题描述


我正在尝试创建一个应用程序,以使用CrudRepository将数据保存到Oracle数据库中。这是我的资料库:

public interface CustomerRepository extends CrudRepository {

List findByEmail(String email);

List findByDate(Date date);

// custom query example and return a stream
@Query("select c from Customer c where c.email = :email")
Stream findByEmailReturnStream(@Param("email") String email);

}

我的application.property看起来像:

spring.datasource.url=jdbc:oracle:thin:@vgdevst-scan.hhs.local:1521/EONDEV.hhslocal
spring.datasource.username=EON_USER
spring.datasource.password=EON_USERD
spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver

虽然我的客户实体类别是:

@Entity
public class Customer {

//http://www.oracle.com/technetwork/middleware/ias/id-generation-083058.html
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CUST_SEQ")
@SequenceGenerator(sequenceName = "customer_seq", initialValue = 1, allocationSize = 1, name = "CUST_SEQ")
Long id;

String name;
String email;

//@Temporal(TemporalType.DATE)
@Column(name = "CREATED_DATE")
Date date;

public Customer(String name, String email, Date date) {
    this.name = name;
    this.email = email;
    this.date = date;
}

public Customer(Long id, String name, String email, Date date) {
    super();
    this.id = id;
    this.name = name;
    this.email = email;
    this.date = date;
}

public Customer() {
}

@Override
public String toString() {
    return "Customer{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", email='" + email + '\'' +
            ", date=" + date +
            '}';
}

public Long getId() {
    return id;
}

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

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public Date getDate() {
    return date;
}

public void setDate(Date date) {
    this.date = date;
}

我正在尝试使用以下方法将新的用户保存到数据库中:

@ SpringBootApplication公共类应用程序实现CommandLineRunner {

private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

@Autowired
DataSource dataSource;

@Autowired
CustomerRepository customerRepository;

public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
}

@Transactional(readOnly = true)
@Override
public void run(String... args) throws Exception {

    System.out.println("DATASOURCE = " + dataSource);
    customerRepository.save(new Customer(new Long(4),"Amit","a.r@state.ma.us",new Date()));
    System.out.println("\n1.findAll()...");
    for (Customer customer : customerRepository.findAll()) {
        System.out.println(customer);
    }

}}

我看不到在肥皂或数据库中添加的新客户。我在这里想念什么?

思路:


您的问题似乎是您正在readOnly

事务中执行save语句。解决方案可能就像删除该属性一样简单。

上一篇:在命令行运行程序构造函数下的springboot应用程序中显示一组元素

下一篇:使用外部身份验证源时如何在Spring Boot中模拟身份验证

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载