싱글톤 패턴 Singleton Pattern - 디자인패턴 싱글톤 패턴 Singleton Pattern 1. 개념 싱글톤 패턴 (Singleton Pattern) 이란 인스턴스를 1개만 생성하는 디자인 패턴이다. 보통은 객체가 사용되는 시점마다 new 를 이용하여 인스턴스를 매번 생성하여 사용하지만,싱글톤 패턴은 오직 하나의 인스턴스를 메모리에 등록하여 동시에 여러 스레드가 공유하여 사용하는 방식을 채택한다. (이 때문에 반드시 Thread-safe가 보장되어야 함) 2. 싱글톤 패턴 - 가장 심플한 버전 # Eager Initialization # 이른 초기화 # Thread-safe 이른 초기화 싱글톤 패턴의 핵심은 다음과 같다. (1) create an object of SingleObject - 클래스 멤버로 인스턴스 생성 (이후 여러 스레드에서 공유되어.. ComputerScience & Embedded/Network & Web 4년 전
[ 오류데이터 ] org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: # 원인 The Exception is straightforward and says : Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements, so the cause is obvious here and if we take a look at the Hibernate Collection mapping documentation it clearly states that:.. 개발/Spring 4년 전
[ 오류데이터 ] Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: # 원인 JPA Entity 설정을 할 때 ManyToOne 필드에 cascade=cascadeType.ALL 을 주어서였다. 만약 A 와 B1, B2 가 있다고 할 때, 1) 처음 A와 B1을 함께 저장 (persist() 또는 save()) 하고, 2) 또다시 B2를 저장하려고하면 3) cascadeType.ALL 속성에 의해서 다시 A를 함께 저장하게 된다. # 해결 종속성 속성을 없애주면 된다. 나의 경우에는 cascade 속성을 아예 없애고 각각 따로 저장해주었다. save() 대신 saveOrUpdate() 를 사용해도 된다고 한다. -> .. 개발/Spring 4년 전
[ 의문점 데이터 ] thymeleaf update/create form 재사용 thymeleaf update/create form 재사용 # 의문점 update 와 create 에서 사용자에게 입력받는 폼의 형태가 같은데, 처음에 실수로 별다른 처리 없이 ModelAndView로 같은 form을 넘겼다. 그 결과 update화면의 form에서 submit을 눌러도 똑같이 createController로 넘어가버렸다. (action값이 그대로 create 주소였기 때문) # 해결 action값을 구분해서 사용하면 하나의 form.html을 재사용해서 사용할 수 있을 것 같았다. mav.addObject("formtype", "update"); Controller 단에서 임의로 formtype 을 넘겨주었다. form.html 에서 action속성의 링크값을 formtype에 따라 바.. 개발/Spring 4년 전
[ 의문점 데이터 ] thymeleaf 로 onClick="location.href=*" 속성 지정 thymeleaf 로 onClick="locationhref=*" 속성 지정 # 의문점 thymeleaf 문법을 이용하여 표에 링크를 주고 싶었는데, onClick location.href 속성을 주려고 하니 이중 삼중으로 따옴표가 들어가서 한참 고민했다. 같은 고민하지 않도록 메모.. # 해결 th:onclick="'location.href=\''+ @{ 걸고자 하는 링크 })} + '\'' 개발/Spring 4년 전
[ 오류데이터 ] javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String #원인 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USER_SEQ_GENERATOR") 원래 Oracle에서 생성한 SEQUENCE로 PK값을 생성하려고 했는데 알고보니 ID 필드를 String으로 설정해놓아서 데이터타입 오류가 발생했다. Oracle의 SEQUENCE는 폐기하고 직접 String으로 저장할 수 있는 방법을 찾아보았다. #해결 @GeneratedValue(genera.. 개발/Spring 4년 전
[ 의문점 데이터 ] difference between @JoinColumn and @PrimaryKeyJoinColumn (@JoinColumn vs @PrimaryKeyJoinColumn) @JoinColumn vs @PrimaryKeyJoinColumn # 의문점 1. @JoinColumn과 @PrimaryKeyJoinColumn의 차이점이 무엇일까 2. @Id + @JoinColumn the same as just @PrimaryKeyJoinColumn? # 해결 1. @JoinColumn과 @PrimaryKeyJoinColumn의 차이점이 무엇일까 This enhanced support of derived identifiers is actually part of the new stuff in JPA 2.0 (see the section 2.4.1 Primary Keys Corresponding to Derived Identities in the JPA 2.0 specification).. 개발/Spring 4년 전
[ 오류데이터 ] org.hibernate.AnnotationException: No identifier specified for entity org.hibernate.AnnotationException: No identifier specified for entity # 원인 @Id annotation 사용 시 import 실수 import org.springframework.data.annotation.Id; (X) # 해결 import javax.persistence.Id; 로 변경 개발/Spring 4년 전