Error msg:
Error shows “Failed to get text for stylesheet (#): No style sheet with given id found”
Ans:
closed all the files in the 'source' tab.
@OneToOne(fetch=FetchType.EAGER) //LAZY @JoinColumn(name="user_profile_id") private Profile getUserProfile() { return userProfile; } FetchType.LAZY = Doesn’t load the relationships unless explicitly “asked for” via getter FetchType.EAGER = Loads ALL relationships
Query queryHot = session.createQuery( "from HotPost ORDER BY popularity DESC"); queryHot.setFirstResult((page - 1) * pageSize); queryHot.setMaxResults(pageSize); solve: Query queryHot = session.createQuery( "from HotPost ORDER BY popularity DESC,id"); ================================== Before: id popularity 1 9 | 2 8 | page 1 3 8 | 5 8 | 6 7 | page 2 7 5 | AFTER: id popularity 1 9 | 2 8 | page 1 3 8 | 4 8 | 5 7 | page 2 6 5 |
正確用法 @OneToOne(mappedBy = "post") @JsonView(View.Detail.class) private HotPost hotPost; 一開始犯傻 @OneToOne(mappedBy = "post") @JsonView(View.Detail.class) Sethotpost = new HashSet<>(0); CautionsCautionsCautions log只會說:Unknown mappedBy in: com.ws.pojo.Post.hotPost, referenced property unknown: java.util.Set.post but @OneToMany remember to use Set
//in pojo (java bean) @BatchSize(size=5) ------------------------------------------------ public void insertOldPost2HotPost() throws Exception{ Session session = sessionFactory.getCurrentSession(); @SuppressWarnings("unchecked") Listposts = session.createQuery("from Post ").list(); int itCount=0; for(Iterator it = posts.iterator(); it.hasNext(); ) { itCount++; Post post = (Post) it.next(); HotPost hotPost = new HotPost(post); session.saveOrUpdate(hotPost); if (itCount % 5 == 0) { session.flush(); session.clear(); } } }