persistence

Confusion: @NotNull vs @Column(nullable = false)

让人想犯罪 __ 提交于 2019-11-26 11:34:42
When they appear on a field/getter of an @Entity , what is the difference between them? (I persist the Entity through Hibernate ). What framework and/or specification each one of them belongs to? @NotNull is located within javax.validation.constraints . In the javax.validation.constraints.NotNull javadoc it says The annotated element must not be null but it does not speak of the element's representation in the database, so why would I add the constraint nullable=false to the column? Ryan Stewart @NotNull is a JSR 303 Bean Validation annotation. It has nothing to do with database constraints

Is it possible to detach Hibernate entity, so that changes to object are not automatically saved to database?

不问归期 提交于 2019-11-26 10:32:52
问题 I have Hibernate entity that I have to convert to JSON, and I have to translate some values in entity, but when I translate values, these values are instantly saved to database, but I don\'t want to save these changes to database. Is there any workaround for this problem? 回答1: You can detach an entity by calling Session.evict(). Other options are create a defensive copy of your entity before translation of values, or use a DTO instead of the entity in that code. I think these options are more

how to make a composite primary key (java persistence annotation)

痴心易碎 提交于 2019-11-26 09:39:49
问题 How to make it so that the table user_roles defines the two columns (userID, roleID) as a composite primary key. should be easy, just can\'t remember/find. In user entity: @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = \"user_roles\") public List<RoleDAO> getRoles() { return roles; } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Integer getUserID() { return userID; } In roles entity: @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = \"user_roles\") public List<UserDAO>

Why can&#39;t environmental variables set in python persist?

烂漫一生 提交于 2019-11-26 09:28:23
问题 I was hoping to write a python script to create some appropriate environmental variables by running the script in whatever directory I\'ll be executing some simulation code, and I\'ve read that I can\'t write a script to make these env vars persist in the mac os terminal. So two things: Is this true? and It seems like it would be a useful things to do; why isn\'t it possible in general? 回答1: You can't do it from python, but some clever bash tricks can do something similar. The basic reasoning

Firebase : What is the difference between setPersistenceEnabled and keepSynced?

谁说胖子不能爱 提交于 2019-11-26 09:10:12
问题 I thought the whole time when I used the following all data for chat conversation will be available offline at any time. Which somehow isn\'t and all nodes are loaded from the server. FirebaseDatabase.getInstance().setPersistenceEnabled(true); Then, according to DOCS : Persistence Behavior : By enabling persistence, any data that we sync while online will be persisted to disk and available offline, even when we restart the app. This means our app will work as it would online using the local

Hibernate: “Field &#39;id&#39; doesn&#39;t have a default value”

耗尽温柔 提交于 2019-11-26 08:58:55
问题 I\'m facing what I think is a simple problem with Hibernate, but can\'t solve it (Hibernate forums being unreachable certainly doesn\'t help). I have a simple class I\'d like to persist, but keep getting: SEVERE: Field \'id\' doesn\'t have a default value Exception in thread \"main\" org.hibernate.exception.GenericJDBCException: could not insert: [hibtest.model.Mensagem] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) at org.hibernate

Generate JPA 2 Entities from existing Database

纵饮孤独 提交于 2019-11-26 08:06:13
问题 How can I generate JPA2 compliant @Entity from existing Databases?. I found this: Question Still its not clear if JBoss will generate compliant JPA2 and also I would like to know if there is a vendor independent way to do this. 回答1: You can use a plugin like Eclipse Dali to do the trick for you. You can refer to the documentation, section 3.11 Generating Entities from Tables. I do not know of any specific vendor independent tool to do this, though. 回答2: Try using OPENJPA Reverse mapping tools

Creating a JSON Store For iPhone

隐身守侯 提交于 2019-11-26 07:32:20
问题 We have loads of apps where we fetch data from remote web services as JSON and then use a parser to translate that into a Core-Data model. For one of our apps, I\'m thinking we should do something different. This app has read-only data , which is volatile and therefore not cached locally for very long . The JSON is deeply hierarchal with tons of nested \"objects\" . Documents usually contain no more than 20 top level items, but could be up to 100K. I don\'t think I want to create a Core Data

Sharing a persistence unit across components in a .ear file

妖精的绣舞 提交于 2019-11-26 07:24:26
问题 In a Java EE 6 application where I\'m using .ear packaging, I\'d like to create a persistence unit that can be accessed from components in different .jar files. However, I\'m not sure how to define this persistence unit. With the @PersistenceContext annotation the lookup only succeeds if the name matches a persistence unit defined in the local persistence.xml file. Is it possible to refer to external persistence units? 回答1: Here are the relevant sections of the JPA 2.0 specification: 8.2

Using javafx.beans properties in model classes

懵懂的女人 提交于 2019-11-26 06:39:40
问题 Is it a correct practice to use JavaFX beans properties in the model classes? I wonder if it is a good practice to use properties in model classes to be able to bind them easier with the view components. I\'m not worried about the availability of those libraries in future because my program will be run on JRE8 or later but the nature of using the JavaFX libraries in the model classes make me skeptical and I\'m worried about current and future incompabilities specially because I want to use