what is the right path to refer a jar file in jpa persistence.xml in a web app?

Taking a look at jsr always works! 8.2.1.6.3 Jar Files One or more JAR files may be specified using the jar-file elements instead of, or in addition to the mapping files specified in the mapping-file elements. If specified, these JAR files will >be searched for managed persistence classes, and any mapping metadata annotations found on … Read more

How do I encode enum using NSCoder in swift?

You need to convert the enum to and from the raw value. In Swift 1.2 (Xcode 6.3), this would look like this: class AppState : NSObject, NSCoding { var idx = 0 var stage = Stage.DisplayAll override init() {} required init(coder aDecoder: NSCoder) { self.idx = aDecoder.decodeIntegerForKey( “idx” ) self.stage = Stage(rawValue: (aDecoder.decodeObjectForKey( “stage” ) … Read more

Refresh and fetch an entity after save (JPA/Spring Data/Hibernate)

Instead of defining EntityManager in each of your resource, you can define it once by creating a Custom JpaRepository. Reference Then use the refresh of your EntityManager in each of your repository directly. Refer the below example: CustomRepository Interface import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.NoRepositoryBean; import java.io.Serializable; @NoRepositoryBean public interface CustomRepository<T, ID extends Serializable> extends JpaRepository<T, ID> … Read more

Generating a globally unique identifier in Java

Pretty sure UUIDs are “good enough”. There are 340,282,366,920,938,463,463,374,607,431,770,000,000 UUIDs available. http://www.wilybeagle.com/guid_store/guid_explain.htm “To put these numbers into perspective, one’s annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens … Read more

Converting from String to custom Object for Spring MVC form Data binding?

Just as a supplement to Mark’s answer, here is what I ended up doing in my controller. @Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Server.class, “serverId”, new PropertyEditorSupport() { @Override public void setAsText(String text) { Server type = (Server) em.createNamedQuery(“Server.findById”) .setParameter(“id”, Short.parseShort(text)).getSingleResult(); setValue(type); } }); } You can also do this using … Read more