We are using some adf internal classes to control our views, we are working on a clustering environment, the problem
is that sometimes the view page get some errors and in the log shows:
2017-11-14T09:42:15.424-02:00] [adf_server1] [ERROR] [] [oracle.adfinternal.controller.state.SessionBasedScopeMap] [tid: [ACTIVE].[[
java.io.NotSerializableException: oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding
Weblogic 12.1.3.0.0 ADF 12c
Does anybody know how can I make adf internal classes serializable or have another solution?
These classes usually uses internal representation of the components, which are not serializable.
I would suggest to not use any ADF internal classes, since:
1) You will get warnings in JDeveloper
2) It is hard to control it!
However if you must, I would wrap declare these members as transient (to solve the serialization problem (that means this property will not be high available).
Related
Background
The application in question is a WebCenter 11g in-house development project using ADF Business Components, JSF 2.0, and Facelets, and is being developed using JDeveloper 11g Release 2, version 11.1.2.4.0. The model project contains an Entity Object with many values for reviewing business projects. The view controller project contains a single page within a bounded task flow, which houses an input form referencing these values for creating and editing reviews. ADF Security features are enabled across the application. In the context of these reviews, intended functionality indicates one class of users can only edit certain "S.E." values, while other users can edit all values and create new reviews. To facilitate this, Entity Attribute-level security has been implemented for the reviews.
The Issue
The review form renders correctly, with the exception of a small, random selection of the values' input elements (eight out of 40) that render as read-only/disabled only when editing an existing record, but have no issue when creating a new record. When testing using the AppModule testing functionality, the same results are observed: the same eight values can be edited by the test user only for new records, while all other values are editable for new and existing records.
Specifics
The View Object and Entity Object Attributes for these values are all configured with the Updatable property set to Always. These values include some of the aforementioned "S.E." values, but not all of them - nor are all of the values at issue included within the "S.E." value group. The test user is set as an administrator for the application, an Application Role to which all Resource Entitlements are granted.
Failed Resolutions
I've attempted changing the View Object and Entity Object Attributes' Updatable attributes to While New and Never, then switching them back to Always - confirming that the changes were made in the XML file with each switch. I've checked and rechecked the ADF Security configuration several times, and confirmed the security for each of those values is identical to that of the other values in the same form/Entity for which the issue does not occur. I've cleaned the application and rebuilt the projects (model and vc) individually before deploying to a freshly launched Integrated WebLogic Server; I've closed and relaunched JDeveloper before rebuilding and redeploying; I've even restarted the computer, as sometimes the nature of my enterprise causes odd issues with JDeveloper that are only resolved by a log out or restart of the entire system. I've also confirmed that the issue occurs on my coworker's machine.
Ground Rules
Due to the nature of my environment, I cannot divulge explicit details of the application, and the following suggestions are unacceptable.
Upgrading JDeveloper
Upgrading Java
Upgrading WebLogic/WebCenter
Upgrading ADF, JSF, or any other library
As it turns out, this issue was caused by an ADF Security/JDeveloper SNAFU. The Entity Attributes in question were renamed (refactored) at some point, and for some reason this change propagated to everything ... except the Attributes' permission configuration. The Attributes and all other references to them held the new names, but their Permission elements in the Entity XML file still held the old names. This was not apparent until reviewing the XML directly, as the JDeveloper UI for ADFBC Entities does not reflect the warning state shown in the XML editor. The solution, then, was to either disable and re-enable Attribute-level security for those Attributes or to manually adjust the Permission elements' parameters within the XML.
For a project I need to have a unique ID generator. So I thought about a Singleton with synchronized methods.
Since a Singleton following the traditional Singleton pattern (private static instance) is shared accross Sessions, I'm wondering if the #Singleton Annotation is working the same way?
The documentation says: Identifies a type that the injector only instantiates once.
Does it mean, that a #Singleton will be independent per User Session (which is bad for an id-generator)? Should I prefer an old school Singleton with Class.getInstance() over an Injection of an #Singleton-Bean?
Or should I use neither nor and provide the Service within an #ApplicationScoped bean?
it musst be guaranteed that only ONE thread, independent of the user session can access the method to generate the next id. (It's not solvable with auto-increment database ids)
Edit: JSF 2.2, CDI and javax.inject.* i'm talking about :)
All those kinds of singletons (static, #javax.inject.Singleton, #javax.ejb.Singleton and #javax.enterprise.context.ApplicationScoped) are created once per JVM.
An object that is created once per user session must be annotated with #javax.enterprise.context.SessionScoped so no, singletons will not be instantiated per user session.
Notice that there are two #Singleton annotations, one in javax.inject and the other in the javax.ejb package. I'm referring to them by their fully-qualified names to avoid confusion.
The differences between all those singletons are subtle and I'm not sure I know all the implications, but a few come to mind:
#javax.ejb.Singleton is managed by the EJB container and so it can handle transactions (#javax.ejb.TransactionAttribute), read/write locking and time-outs (#javax.ejb.Lock, #javax.ejb.AccessTimeout), application startup (#javax.ejb.Startup, #javax.ejb.DependsOn) and so on.
#javax.enterprise.context.ApplicationScoped is managed by the CDI container, so you won't have the transaction and locking features that EJB has (unless you use a post-1.0 CDI that has added transactions), but you still have lots of nice things such as #javax.enterprise.inject.Produces, #javax.annotation.PostConstruct, #javax.inject.Named, #javax.enterprise.inject.Disposes (but many of these features are available to EJBs too).
#javax.inject.Singleton is similar to #ApplicationScoped, except that there is no proxy object (clients will have a reference to the object directly). There will be less indirection to reach the real object, but this might cause some issues related to serialization (see this: http://docs.jboss.org/weld/reference/latest-2.2/en-US/html_single/#_the_singleton_pseudo_scope)
A plain static field is simple and just works, but it's controlled by the class loader so in order to understand how/when they are instantiated and garbage collected (if ever), you will need to understand how class loaders work and how your application server manages its class loaders (when restarting, redeploying, etc.). See this question for more details.
javax.inject.Singleton - When used on your bean, you have to implement writeResolve() and readReplace to avoid any serialization issues. Use it judiciously based on what your bean actually has in it.
javax.enterprise.context.ApplicationScoped - Allows the container to proxy the bean and take care of serialization process automatically. This is recommended to avoid unprecedented issues.
For More information refer this page number 45.
I'm working on a 2-tier WPF/EF Code First application. I did a lot of googling but couldn't find a sample implementation of what I was looking for... was hoping that someone on this forum could help me out. Here are the requirements:
On Application Start up
Open a DBContext
Cache the reference data in various maps/lists when the application starts
Close Context.
When user opens a form
Open a DBContext (I'm using UnitOfWork pattern here)
Fetch a fresh copy of Entity from context for Editing.
Call SaveChanges() when Save button is hit.
Close the Context.
The problem manifests when I use an object from Cache to change a navigation property.
e.g. use a drop down (backed by cache which was created using a different DBContext) to set Department navigation property.
The UnitOfWork either throws an exception saying entity was loaded in another DBContext (When Department is lazy loaded DynamicProxy) or inserts a new row in Department table.
I couldn't find even a single example where reference data was being cached... I can't believe that no one came across this issue. Either I'm not looking in the right place or not using the right keywords.
I hope this is doable using EF. I'd appreciate if you can share your experiences or post some references.
I'm kinda new to this so would like to avoid using too many frameworks and just stick to POCO with WPF/EF stack.
Try to attach your cached item (probably, you'd make a clone before attaching):
var existingUnicorn = GetMyExistingUnicorn();
using (var context = new UnicornsContext())
{
context.Unicorns.Attach(existingUnicorn);
context.SaveChanges();
}
Refer to Using DbContext... article.
You mention you are using WPF for this, in that case you don't necessarily have to open a new DBContext every time you want to interact with the domain layer. (Apologies if this goes against UoW that you are keen on using)
Personally I have been using code-first development for a desktop application, and I have found that pooling the contexts (and therefore the connection) prevents this problem, and hasn't led to any problems thus far.
In principle, as soon as the application is launched, a main Context object is opened for the main UI thread, and stays open throughout the duration of the application lifetime. It is stored statically, and is retrieved by any Repository class when they are used.
For multi-threading scenarios, any background threads are free to open up additional contexts and use them in Repositories to prevent any race conditions.
If you were to adopt this approach, you would find that as all repositories share the same context, there are no issues arising from object context tracking.
I ended up defining int foreign key property in addition to navigation.
In my application I only modify the int property and use the navigation property for displaying the details (read only controls).
While this works it makes the application a little fragile and sometimes inconsistent.
although this blog claims that the FK & Navi properties are synced by EF but I couldn't get it to work.
http://coding.abel.nu/2012/03/ef-code-first-navigation-properties-and-foreign-keys
In a Silverlight 4 app I'm trying to instantiate an object whose type isn't known until run-time, using this code:
Assembly assembly = Assembly.LoadFrom("Name.Of.Some.dll");
Type type = assembly.GetType("Full.NameSpace.And.ClassName");
object o = Activator.CreateInstance(type);
However, the Assembly.LoadFrom() call results in an exception:
{System.MethodAccessException: Attempt by security transparent method 'Mosaic.Layers.LayerParamChangeHandlerInfo.CreateParamHandler()' to access security critical method 'System.Reflection.Assembly.LoadFrom(System.String)' failed.
I've done some Googling for the error, but I still can't figure out why I'm getting the exception (something related to the assemblies being strongly signed, I believe) and, more importantly, how to solve the problem and create my object.
You are not allowed to call this method from your own code, cause its security critical and restricted to be used only internal in .NET Framework.
Do not use this member in your application. If you do, your code will throw a MethodAccessException. This member is security-critical, which restricts it to internal use by the .NET Framework for Silverlight class library.
The only available Load method for assemblies in Silverlight is Assembly.Load(string). If you want to dynamically load an assemblies, take a look at this approach.
We are working on a POC where we have following architecture (MVVM),
WPF(Client) + WCF + Model(DataAccess)+ ADO.Net Entity Framework 4.0 (with SQL Server 2008 R2 as DB)
All are different projects.
In the DataAccess layer we have created different Entity Models(edmx) based on the functionality. The tables under perticular flow are grouped and created different entity models. We are using self tracking entities to and fro to communicate with the WPF client through wcf service. For Single model everything works fine. But when we created a Multiple models then few issues started coming. Mutliple models have few duplicate tables/entities. Two probels are,
1) When we try to access entities from different models mutiple objects "ObjectChangeTracker" are getting created.
E.g.
CompanyModel(edmx) - Company(Entity) - ObjectChangeTracker, ObjectState
ProductModel(edmx) - Customer(Entity) - ObjectChangeTracker1, ObjectState1
OrderModel(edmx) - Oder(Entity) - ObjectChangeTracker2, ObjectState2
Is there any way to avoid this?
2) There are few tables which shared across the Models, E.g. Company(Entity) is used in All above mdoels. During compile time it does not thow any error. But run time It gives error saying "Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type "Company"".. To resolve this, we renamed the entities with some prefix to make them Unique. Is there any other way we can resolve this without changing the name of the entity in the same assembly?
Thanks in advance and appreciate if anyone has approach for these issues.
Thanks,
Kiran
1) Are you enabling the ChangeTracker always when you grab entities from your data access?
I guess you can't avoid what is created unless you use the POCO Template. It has some more job to be done in some matters but you will have lighter objects. You must then manage the entity state by yourself. I think its good to stay on selftracking but while you use WCF you should change the collection type to FixUpCollection as i can remember to work better with your WCF Service. HINT: Don't forget to disable lazy loading or else you will end up having all the child records you night not want when the entities are serialized.
2) Try and seperate the models in different assemblies, is a better practice and i think you will overcome these problems. I worked this way and its ok.
Hope i helped....