What is the meaning of "Frozen" attribute? - java

My model.xml file contain following code fragment. but I don't know why they are used.I used Spring and Hibernate technologies to build the project. hopes some expert explanation about this code fragment and the attributes?
<one-to-one fetch-type="lazy" name="followUp" type="FollowUp" synthetic="true"
nullable="true" access="frozen">
<documentation>Synthetic property of the latest follow ups made for
this Prescription.
</documentation>
</one-to-one>

Related

Ignoring Field in Apache Olingo

Currently my Project is using the JPA for the Database Connection.
I'm also using the default OdataJPA Processor.
How can i achieve not to include certain fields for example ("password") in my odata2 API response. Or do I really have to implement a customOdataJPAProcessor?
The easiest way for excluding some JPA entity attributes is to define a JPA-EDM mapping model. This is basically an XML file which adheres to this schema. You can read more about it in the documentation here: redefining OData JPA metadata.
You have two different ways of linking the mapping model XML, either you specify a file name of a file located in the WEB-INF folder (assuming that you are building a WAR) or, if this is not flexible enough, you can create a JPA EDM extension and return the mapping model file as a stream.
This is how such a file may look like:
<?xml version="1.0" encoding="UTF-8"?>
<JPAEDMMappingModel xmlns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping">
<PersistenceUnit name="My_Persistence_Unit">
<JPAEntityTypes>
<JPAEntityType name="MyEntity">
<EDMEntityType>MyEntity</EDMEntityType>
<EDMEntitySet>MyEntities</EDMEntitySet>
<JPAAttributes>
<JPAAttribute name="attribute" exclude="true" />
</JPAAttributes>
<JPARelationships />
</JPAEntityType>
</JPAEntityTypes>
<JPAEmbeddableTypes />
</PersistenceUnit>
</JPAEDMMappingModel>

make openJPA caching only chosen tables

How can I set openJPA cache so that it works only for chosen entities, maybe I need use some annotaion over they?
my persistence.xml contains:
<property name="openjpa.DataCache" value="true"/>
<property name="openjpa.RemoteCommitProvider" value="sjvm"/>
but thats settings works for all my entities(tables), so i want to cache for example only that table:
#Entity(name = "IsoCountryCodes")
#Table(name = "ISO_COUNTRY_CODES", schema = "ANALYSIS")
#DataCache(timeout=120000)
public class IsoCountryCodes implements Serializable{
....
}
But #DataCache doesnt fix it, its only set the timeout of cache saving.
UPDATE:
I cannot use openJPA 2.0 cause my project deployed on WebLogic 10.36 and have provided KODO openJPA 1.3.
Also i try to include only chosen entities by adding property:
property name="openjpa.DataCache" value="true(Types=foo.bar.FullTimeEmployee)"
but got this error:
org.apache.openjpa.lib.util.ParseException: There was an error while setting up the configuration plugin option "DataCache". The plugin was of type "class kodo.datacache.KodoConcurrentDataCache". The plugin property "Type" had no corresponding setter method or accessible field. All possible plugin properties are: [CacheSize, EvictionSchedule, FailFast, NAME_DEFAULT, Name, SoftReferenceSize].
Can you help me?Maybe you know other ways to exclude or include entitites from caching, maybe with Ehcache usage?
<property name="openjpa.DataCache" value="true"/>
That enables the L2 cache for all Entities. If you are using jpa-2.0, try adding <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> to turn the cache on. Also, replace the #DataCache annotation with a #javax.persistence.Cacheable annotation.

Dozer Boolean mapping Eclipse error

I am using Dozer to map objects. But I am getting an wired error message
Property active for class com.edfx.adb.persist.entity.Customer cannot
be read from.
in the Dozer Mapping Editor of Eclipse, I have Dozer plugin installed in Eclipse. This is the mapping I have:
<mapping>
<class-a>com.edfx.adb.persist.entity.Customer</class-a>
<class-b>com.edfx.adb.web.dto.CustomerDTO</class-b>
<field>
<a get-method="isActive">active</a>
<b get-method="isActive">active</b>
<a-hint>java.lang.Boolean</a-hint>
<b-hint>java.lang.Boolean</b-hint>
</field>
</mapping>
Here active is the field with type boolean in Customer and CustomerDTO class.
I am unable to remove or hide the error message. Also don't know why it is showing. And for this error Eclipse showing error in whole project which is undesirable.
Any information would be very helpful to me.
I would try deleting hints. In this scenario I think you donĀ“t need them.
But for best solution can you post your code for the entity and the DTO.

Trying to specify default value for property in hibernate

I'm getting the following error message from hibernate when attempting to insert a row into a table:
org.hibernate.exception.ConstraintViolationException: Column
'priority' cannot be null
I know that I could put a line into the code to set the value but there are many other instances where the program relies on the default value in the database (db is mysql).
I read somewhere that you can provide a default value in the hbm.xml file but hibernate is not recognizing it. Here's the corresponding section from JobQueue.hbm.xml
<property name="priority" type="integer">
<column name="priority" default="0" />
</property>
I suppose another option would be to modify the JobQueue.java file that gets generated (I'm using eclipse hibernate tools to auto generate the hibernate classes) but for now I'd like to try to get the hbm.xml configuration to work.
I'm using version 4.1.3 of the hibernate libraries and eclipse hibernate tools 3.4.0.x.
default="0" is only relevant for SchemaExport which generates the database schema. other than that hibernate completely ignores this setting. you could try to set not-null="true" for the column.
Unless you are not able to recreate the whole database schema, you can set the default value in the variable initialization.
In your model set the priority to 0 in the initialization.
In your class:
private Integer priority = 0;
I ended up modifying the JobQueue.java POJO to set the default value. To make sure that the Code Generation of hibernate tools wouldn't overwrite this change, I set it up so that the code generation generates the files in a temp folder and then the necessary files are copied over to the permanent source location.

Hibernate's generator class not really working?

Asking this question here after hours of frustration with me and my Eclipse. Hoping to find some respite here.
I'm trying to save a pojo object into MySQL database via Hibernate 3.0. Basically my requirement is: I need to assign the id for the object before save and not let Hibernate do it for me.
For this I looked up in the documentation and saw that <generator class="assigned"/> perfectly fits my bill. Consequently I updated by .hbm.xml file with the following for the id:
<id name="id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
My pojo matches .hbm.xml file to the T.
I'm setting all the parameters including the ID of my pojo and calling Hibernate's saveOrUpdate(object) method.
If it's of any help, the ID column of my database table has "auto-inc" disabled.
Unbelievably, when I look at the database table contents, a row has been inserted with Hibernate's own ID and not what I had set.
How's it possible? Is there anything else affecting the ID? Am I missing on something? What's the work around?
My hibernate.properties looks like below(if it's of any help):
hibernate.connection.driver_class =com.mysql.jdbc.Driver
hibernate.dialect =org.hibernate.dialect.MySQLDialect
hibernate.connection.url =jdbc:mysql://localhost/dbdbdbdbdb
hibernate.connection.username=root
hibernate.connection.password=password
hibernate.connection.pool_size=10
jdbc.batch_size=30
hibernate.show_sql=true
hibernate.current_session_context_class=true
hibernate.hbm2ddl.auto=validate
hibernate.cglib.use_reflection_optimizer=false
hibernate.generate_statistics=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory
Well, hoax alarm!. It was really an issue with Eclipse-Tomcat integration. I had to clean up Tomcat's directories and republish before the hbm files could take effect.
Tip: If you run ant within Eclipse, be sure to keep refreshing Eclipse workspace every now and then. Learning some things the hard way.
You can write your custom sequence generator class to return ids suitable to your requirement. For more details follow: http://danu-javastuff.blogspot.com/2009/01/custom-id-generator-class-for-hibernate.html

Categories