我是春天的新手。上图显示了我的数据库架构:
我需要每分钟为每个电台下载一个新的实时数据,我必须将其分配给该电台。我想设法:
这就是我想做的事情,如果我采取完全不同的方式来做这样的事情,任何建议都会受到赞赏。
站类是这样的:
@RooJavaBean
@RooToString
@RooJpaActiveRecord(finders = { "findStationsByNum" })
@RooJson
public class Station {
private String address;
private String name;
private Integer num;
@ManyToOne(cascade = CascadeType.ALL)
private Location location;
@ManyToOne
private City city;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "station", fetch=FetchType.LAZY)
private Set<RealTimeData> real_time_data = new HashSet<RealTimeData>();
}
RealTimeData类是这样的:
@RooJavaBean
@RooToString
@RooJpaActiveRecord(finders = { "findRealTimeDatasByCollect_dateEquals" })
@RooJson
public class RealTimeData {
private Integer available_bike_stands;
/* ... ... ... */
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "M-")
private Date collect_date;
@ManyToOne
private Station station;
}
答案 0 :(得分:0)
您可以在此处阅读解决方案的详细信息: http://forum.spring.io/forum/spring-projects/roo/106714-bulk-operations-with-spring-roo
然而,合成它建议使用它:
@PersistenceContext
private EntityManager entityManager;
@Transactional
public void storeList(List<MyEntity> entities) {
int imported = 0;
for (MyEntity e: entities) {
entityManager.persist(e);
if (++imported % 50 == 0) {
entityManager.flush();
entityManager.clear();
}
}
}
或者如果您使用的是Spring Roo:
@Transactional
public void storeList(List<MyEntity> entities) {
int imported = 0;
for (MyEntity e: entities) {
e.persist();
if (++imported % 50 == 0) {
e.flush();
e.clear();
}
}
}
在persistence.xml的属性中设置:
<property name="hibernate.jdbc.batch_size" value="50"/>