正在尝试将数据插入我的数据库表“ claim_grouping_history”。但是Entity类的.save(entity)方法不起作用。
claimGroupingHistoryRepository.save(claimGroupingHistory);
,此行不起作用,也没有日志信息。
请找到我的模型课:
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@JsonInclude(NON_EMPTY)
@Table(name = "claim_grouping_history")
@EqualsAndHashCode(of = "id")
public class ClaimGroupingHistory implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonIgnore
private Long id;
@Column(name = "dealer_code")
private String dealerCode;
@OneToOne
@JoinColumn(name = "created_by", referencedColumnName = "id", updatable = false)
private User createdBy;
@Column(name = "created_at", updatable = false)
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime createdAt;
@Column(name = "last_updated_at")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime lastModifiedAt;
}
请找到我的Save方法实现:
@Override
@Transactional
public void updateClaimGroupingKeyForDealer(String dealerId, GroupingKeyResource groupingKeyResource, String userId){
User user = userRepository.findOne(userId);
ClaimGroupingHistory claimGroupingHistory = null;
System.out.println("History section---> if");
claimGroupingHistory = new ClaimGroupingHistory();
claimGroupingHistory.setDealerCode(dealerId);
claimGroupingHistory.setCreatedAt(new DateTime());
claimGroupingHistory.setCreatedBy(user);
System.out.println("History section---> if"+claimGroupingHistory.toString());
claimGroupingHistoryRepository.save(claimGroupingHistory);
}
请找到我的存储库类:
public interface ClaimGroupingHistoryRepository extends PagingAndSortingRepository<ClaimGroupingHistory, Long>, JpaSpecificationExecutor<ClaimGroupingHistory> {
@Query("SELECT c FROM ClaimGroupingHistory c WHERE c.dealerCode = :dealer")
ArrayList<ClaimGroupingHistory> getClaimGroupingHistory(@Param("dealer") String dealer);
@Modifying
@Query(value = "UPDATE ClaimGroupingHistory c SET c.createdBy = :createdBy, c.lastModifiedAt = :lastModifiedAt where c.dealerCode = :dealerCode")
void updateClaimGroupingHistory(@Param("createdBy") User lastModifiedBy,@Param("lastModifiedAt") DateTime lastModifiedAt, @Param("dealerCode") String dealerCode);
}
请找到我的persistance.xml文件:
<persistence-unit name="mysql-core" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
<property name="hibernate.jdbc.batch_size" value="300"/>
<property name="hibernate.query.plan_cache_max_soft_references" value="128"/>
<property name="hibernate.show-sql" value="true"/>
</properties>
</persistence-unit>
</persistence>