반응형
@Entity
@Table(name = "board")
public class Board {
    @Id
    @Column(name = "keyword_news_id")
    private int id;

    @Id
    @Column(name = "board_no")
    private int boardNo;

 

이와 같이 엔티티를 설정하게 되면 

 

Composite-id class must implement Serializable

 

이와 같은 에러가 발생하게 된다.

 

에러의 원인은 아래와 같다.

The session object needs to be serializable hence all objects referenced by it must be serializable as well. The id is used as a key to index loaded objects in the session. In case of CompositeId s the class itself is used as the id.

세션에서 객체가 로드 될때 키의 index를 id로 사용하기 위해서는 각 객체가 Serializable 된 상태어야 된다.

라고 해석 된다.

//TODO Serializable 이 된다는게 정확히 어떤의미 인지 다시 한번 찾아보자.

 

아래와 같이 Serializable 을 상속 받으면 해결 된다.

@Entity
@Table(name = "board")
public class Board implements Serializable {
    @Id
    @Column(name = "keyword_news_id")
    private int id;

    @Id
    @Column(name = "board_no")
    private int boardNo;
반응형

'IT > JAVA' 카테고리의 다른 글

모바일 체크 로직 예제  (0) 2019.04.28
[JAVA] String To Date , Date To String  (0) 2018.11.29
반응형

자바에서 모바일인지 아닌지 체크하는 로직 예제

 

String userAgentHeader = getRequest().getHeader("user-agent");
	if(userAgentHeader != null){
		userAgentHeader = userAgentHeader.toLowerCase();
	}
	if(userAgentHeader.matches(".*(android.+mobile|iphone|ipad|ipod|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino).*")){
		getResponse().sendRedirect(Configuration.getInstance().getString("tradekorea_mobile_host"));
		return;
	}

 

 

반응형

'IT > JAVA' 카테고리의 다른 글

[JPA] Composite-id class must implement Serializable 에러  (1) 2019.05.28
[JAVA] String To Date , Date To String  (0) 2018.11.29
반응형

정말 자주 쓰는 기능이지만 매번 찾고 매번 헷갈리는것 같다



String to Date

String from = "2018-11-28 10:10:10";

SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date to = transFormat.parse(from);


Date to String 


Date from = new Date();

SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String to = transFormat.format(from);


반응형

'IT > JAVA' 카테고리의 다른 글

[JPA] Composite-id class must implement Serializable 에러  (1) 2019.05.28
모바일 체크 로직 예제  (0) 2019.04.28

+ Recent posts