Caching read-only entity beans in EJB 3.1 - glassfish-3

How do I go about marking an entity bean (let us say that I have an "Country" entity bean which holds a record about a country that never changes) read-only on a Glassfish 3.1 with EJBs 3.1?
There seems to be a way to mark column immutable, but information is very scarce and whatever I tried didn't really work.
Any ideas?

Using EclipseLink you can use the JPA exensions of EclipseLink and put the #ReadOnly on the entity. For query you can add the query hint READ_ONLY to the query:
query.setHint(QueryHints.READ_ONLY, HintValues.TRUE);
For details on this, see http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Declaration_of_Read-Only_Classes
and
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Read_Only

Related

Entity Framework Core Scaffold - Dynamic Schema Name

I'm having an issue at the moment where, we have a database which was already created, so used ef scaffold to create a model of it - the schema the model was created against is called "xxxx-dev".
Now, this has been fine, but in preparation to go live, I created a new DB server and provisioned the database to be called "xxxx-live". Switched the connection string, and attempted a query against it, and got an error.
It seems that scaffolding has hard-coded the schema name into every table in the OnModelCreating call, for example:
modelBuilder.Entity<xxxx>(entity =>
{
...
entity.ToTable("xxxx", "xxxx-dev");
...
});
This is a bit of an issue as going forward, we might have multi-tenant sites based on the same database, and obviously the query overriding the connection string every query isn't a great experience.
Is there anyway to configure the schema name, either in the Scaffold, or at runtime? I've done a bit of searching around and can't seem to see a solution.
Thanks,

How to use Doctrine Extensions in Api Platform

I'm using stofDoctrineExtensionsBundle in a Symfony 4 project with Api Platform. I've sluggable and timestampable extensions actives. It works like a charm when I persist the entities manually, ie in the fixtures, but when I persist via the POST collectionOperations, it doesn't work, and said that those fields (slug, createdAt and updatedAt) are required.
I can't find a solution for this after several days.
Thank you very much (this is my first question here).
Those fields should not be required.
The sluggable and timestampable extensions set their values onFlush, a doctrine event that calculates what has changed in your objects and runs the SQL queries to actually update the database. API Platform will make that happen at the WRITE stage, which is AFTER validation so validation will not see those values. Remove any assersions for those fields like #Assert\NotBlank, #Assert\NotNull.
If the fields are not nullable in the configuration of their mapping (for example #ORM\Column()) they will appear as required in the swagger, open api or Hydra documentation generated by API Platform. Some clients, like the admin client and those from the client generator, use this documentation and will therefore make the inputs for those properties required.
Add the following annotations to the doc blocks of those properties:
* #ApiProperty(required=false)
This annotation requires near the top of the file:
use ApiPlatform\Core\Annotation\ApiProperty;

Entity Framework Sql Azure mapping error

Setup:
Asp.NET Web Api 2 (Running in Azure Cloud service, 3 instances), Entity Framework 6.1 and Sql Azure
Problem
My application started reporting a ton of weird errors all of a sudden.
When using EF to get entities from the database these types of errors are reported:
"The '{PropertyName}' property on '{TableName}' could not be set to a 'System.String' value. You must set this property to a non-null value of type 'System.Int64'"
And
"The '{PropertyName}' property on '{TableName}' could not be set to a 'System.Int64' value. You must set this property to a non-null value of type 'System.String'."
My interpretation is that the database is returning non-matching objects compared to what I'm trying to map against, but I can't see why that would start happening out of the blue, after running just fine for millions of requests.
While I was writing this I rebooted the api instances and now the errors are gone.
Any help in figuring this out will be highly appreciated.
Turned out the probable cause was a mistake in the setup of the unit of work pattern. Note to self: Do not create a new dbcontext to replace a dbcontext that is being used :)

Same stateless bean in two ears

I have the same EJB module with a bean inside an EAR that is server side and an EAR that is the client side.
Can I have this situation?
Because I'm getting this error http://justpaste.it/gfs3
without understand how to fix it.
You have answer in the stack trace:
The short-form default binding 'com.demo.view.RitornaPersonaRemote'
is ambiguous because multiple beans implement the interface :
[RitornaPersonaSenzaClientEAR#RitornaPersonaSenzaClient.jar#RitornaPersona,
RitornaPersonaWebSenzaClientEAR#RitornaPersonaSenzaClient.jar#RitornaPersona].
Provide an interface specific binding or use the long-form default binding on lookup.]
If you are asking whether you may have same EJB jar in multiple project - the answer is yes you can. However during deployment you have to use long-form JNDI, provide different JNDI name for beans in other module or disable short names. You cannot register two beans under same name.
Long name would be in the form RitornaPersonaSenzaClientEAR#RitornaPersonaSenzaClient.jar#com.demo.view.RitornaPersonaRemote
See detailed info here - EJB 3.0 and EJB 3.1 application bindings overview
UPDATE
To disable short names perform the following steps:
Go to Application servers > server1 > Process definition > Java Virtual Machine > Custom properties
Define new custom property com.ibm.websphere.ejbcontainer.disableShortDefaultBindings with value * to disable short bindings for all apps or AppName1|AppName2 to just disable short bindings in selected apps.
Example default bindings are shown in SystemOut.log:
The binding location is: ejblocal:JPADepEar/JPADepEJB.jar/TableTester#ejb.TableTester
The binding location is: ejblocal:ejb.TableTester
The binding location is: java:global/JPADepEar/JPADepEJB/TableTester!ejb.TableTester
And with disableShortDefaultBindings property set there is no short form:
The binding location is: ejblocal:JPADepEar/JPADepEJB.jar/TableTester#ejb.TableTester
The binding location is: java:global/JPADepEar/JPADepEJB/TableTester!ejb.TableTester
There is a bug in the documentation and the correct property is com.ibm.websphere.ejbcontainer.disableShortDefaultBindings not com.ibm.websphere.ejbcontainer.disableShortFormBinding
In my case:- i did install abc.ear and xyz.ear both ear was independent do dependency with each other.
I was calling abc.ear using client-lookup but that was giving me
com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.
[Root exception is com.ibm.websphere.ejbcontainer.AmbiguousEJBReferenceException: The short-form default binding
'com.ejb.abc' is ambiguous because multiple beans implement the interface :
[xyz-ear#rabc-ejb-1.0.jar#abcInrerfaceImpl, rabc-ear#rabc-ejb-1.0.jar
abcInrerfaceImpl]. Provide an interface specific binding or use the long-form default binding on lookup.]
my Solution was:-
i removed the abc.jar that was inside another application(xyz.ear)
C:\Program Files\IBM\WebSphere\AppServer\profiles\AppSrv01\wstemp\92668751\workspace\cells\mypc00Node01Cell\applications\xyz-ear.ear
'
Then solution client-lookup works fine.
To avoid this in future this is better practice to create separate node on your IBM-WAS server and install both application on different node.
So both application component will not mess up.

How can I get an Alfresco ContentService object?

I am attempting to read the content of a file in Alfresco. I have seen examples that use
ContentService. Unforunately, when I try to use the example code, the ContentService
is not available.
I have added ContentService as a managed property of my managed bean in faces-config.xml
<managed-property>
<property-name>contentService</property-name>
<value>#{ContentService}</value>
</managed-property>
In my java code, I am using
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
// contentService is an instance variable.
this.contentService = serviceRegistry.getContentService();
I am getting this Exception:
javax.faces.el.EvaluationException: Exception while invoking expression #{DeployAssetQADialog.start}
caused by:
javax.faces.el.PropertyNotFoundException: Bean: com.XXXXXXXXXX.CCCCCCCC.DeployAssetDialog, property: contentService
Can anyone tell me if there is something that I am missing? Thanks
PropertyNotFoundException sounds like your managed bean is missing a setter method.
How to expose spring managed beans to jsf may depend on the spring and/or jsf version you are using. Have a look at Spring beans injected into JSF Managed Beans for an example.
Finally, Make sure your Alfresco spring context is initialized before jsf kicks in.
Many issues in code
1) For each services which are injected you need to add getter setter method for them.
If you add getter setter for contentservice you can get rid of your error.
2) Other thing is you are trying to get conentservice though service registry in that case you need to inject service registry and add getter setter for that. Otherwise get contentservice instance directly as it is injected though faces-config and provided you have added getter setter for it you can directly use that instance of contentservice.

Resources