草庐IT

pre_save_parent

全部标签

java - Hibernate:必须在调用 save() 之前手动分配此类的 id

我在使用Hibernate和oneToMany映射时遇到了一些问题。这是我的功能:Locationlocation=newLocation();location.setDateTime(newDate());location.setLatitude(lat);location.setLongitude(lon);location=this.locationDao.save(location);merchant=newMerchant();merchant.setAddress(address);merchant.setCity(city);merchant.setCountry(cou

node.js - Mongoose .pre ('save' ) 不会触发

我有以下mongoose.model('quotes')的模型:varmongoose=require('mongoose');varSchema=mongoose.Schema;varquotesSchema=newSchema({created:{type:String,default:moment().format()},type:{type:Number,default:0},number:{type:Number,required:true},title:{type:String,required:true,trim:true},background:{type:String

node.js - Mongoose .pre ('save' ) 不会触发

我有以下mongoose.model('quotes')的模型:varmongoose=require('mongoose');varSchema=mongoose.Schema;varquotesSchema=newSchema({created:{type:String,default:moment().format()},type:{type:Number,default:0},number:{type:Number,required:true},title:{type:String,required:true,trim:true},background:{type:String

node.js - 跳过或禁用 Mongoose 模型 save() 调用的验证

我希望创建一个保存到MongoDB的新文档,无论它是否有效。我只想在模型保存调用时暂时跳过Mongoose验证。在我导入CSV的情况下,CSV文件中不包含一些必填字段,尤其是其他文档的引用字段。然后,以下示例未通过mongoose验证所需检查:varproduct=mongoose.model("Product",Schema({name:{type:String,required:true},price:{type:Number,required:true,default:0},supplier:{type:Schema.Types.ObjectId,ref:"Supplier",r

node.js - 跳过或禁用 Mongoose 模型 save() 调用的验证

我希望创建一个保存到MongoDB的新文档,无论它是否有效。我只想在模型保存调用时暂时跳过Mongoose验证。在我导入CSV的情况下,CSV文件中不包含一些必填字段,尤其是其他文档的引用字段。然后,以下示例未通过mongoose验证所需检查:varproduct=mongoose.model("Product",Schema({name:{type:String,required:true},price:{type:Number,required:true,default:0},supplier:{type:Schema.Types.ObjectId,ref:"Supplier",r

java - 如何使用 java "Open"和 "Save"

我想在java中创建一个“打开”和“保存”对话框。我想要的示例如下图所示:打开:保存:我该怎么做呢? 最佳答案 您想使用JFileChooser对象。它将打开并成为模态,并阻塞在打开它的线程中,直到您选择一个文件。打开:JFileChooserfileChooser=newJFileChooser();if(fileChooser.showOpenDialog(modalToComponent)==JFileChooser.APPROVE_OPTION){Filefile=fileChooser.getSelectedFile();

java - 如何在 save() 之前阻止 spring data JPA 执行 SELECT?

我们正在针对现有数据库编写一个新应用程序。我正在使用SpringDataJPA,并且只是在做一个MyRepository.save()在我的新实体上,使用MyRepositoryextendsCrudRepository我在日志中注意到hibernate在插入之前执行了一个Select操作,并且它们需要很长时间,即使在使用索引时也是如此。我在这里搜索过这个,answersI'vefound通常与Hibernate相关。我对JPA很陌生,看起来JPA和Hibernate非常紧密地交织在一起,至少在SpringData的上下文中使用它时是如此。链接的答案建议使用Hibernatepersi

java - Spring JpaRepository : delete() with subsequent save() in the same transaction

我的实体同时具有自动生成的主键(id)和业务键(命名空间)。我需要通过替换旧记录来更新记录。所以,我正在按业务键搜索它,删除它并保存一个新实体。如果它自己的事务中的每个操作都有效。但是一旦我把它们都放在同一个事务中,当save()被执行时,delete()还没有被执行,所以我得到了一个约束违规。transactionTemplate.execute(status->{MyEntityoldEntity=repository.findByNamespace(namespace);if(oldEntity!=null){repository.delete(oldEntity);}repos

java - hibernate 异常 : Pre-bound JDBC Connection found

我有以下问题:在多用户springhibernateweb应用程序中,我们遇到以下异常。检查日志记录时,它发生在多个地方。我搜索了一下,也检查了Stackoverflow,但我找不到解决方案:Pre-boundJDBCConnectionfound!HibernateTransactionManagerdoesnotsupportrunningwithinDataSourceTransactionManageriftoldtomanagetheDataSourceitself.ItisrecommendedtouseasingleHibernateTransactionManagerf

java - 以编程方式启用 Spring Security pre-post-annotations

我有SpringWebMVC应用程序,在Controller方法上使用@PreAuthorize和@PostAuthorice注释。但是这些注释被忽略了,因为我没有在我的SpringSecurity中启用它。如果我有一个spring-security.xml我可以使用以下行启用它:不幸的是,我有一个完整的基于注释的配置。Spring-Security原则上适用于我的应用程序。我的问题:如何使用基于注释的MVC配置启用pre-post-annotation?Spring版本:4.0.5.RELEASESpring-Security-版本:3.2.4.RELEASE这是我的WebSecur