I'm working in a Java project where I need to make automatically an application (ear file) multitenant. A minimum configuration (view here http://wiki.eclipse.org/EclipseLink/Development/Indigo/Multi-Tenancy) to enable multitenancy in a given entity is :
#Entity
#Table(name="EMP")
#Multitenant
public Employee() {
...
}
My goal is to add dynamically the #Multitenant annotation to all entities and my question is: is there a solution other that editing the bytecode to add this annotation?
Thanks in advance.
You could use an orm.xml if you don't want to change the code.
You could also use a SessionCustomizer to configure a MultitenantPolicy on each ClassDescriptor.
Related
We have a requirement to disable #entity based on configuration. is it possible?
We dont want to create a table so we should disable only few entity.
I can think of a couple of ways to handle this requirement, but the simplest one (assuming you're using Spring Boot) would probably be to group the required and optional entities in separate packages, and then setup the main configuration to include entities from the required package:
#SpringBootApplication
#EntityScan({"requiredpackageone", "requiredpackagetwo", ...})
public class MainApplication {
...
}
and then, enable entity scanning for the optional package, in an optional configuration:
#Configuration
#ConditionalOnProperty(...) // or #Profile, whichever works for you
#EntityScan("optionalpackage")
public class AdditionalEntityConfig {
// the class itself can be empty
}
Entity Framework 7 reverse engineering tool does not generate the POCOs as partials. Is there a specific reason for that?
Before EF7 we used to get partial classes so I could extend the functionality of POCOs. I was using partial classes to map the Id property to the Primary key property as shown below;
public partial class User: EntityBase
{
public override int Id
{
get { return UserId; }
set { UserId= value; }
}
}
How can I do that in EF7?
Thank you.
It was just an oversight. An Entity Framework bug was raised on this (see https://github.com/aspnet/EntityFramework/issues/3428). It was fixed today (Oct 16, 2015) - and will be in tonight's nightly build.
As a workaround the scaffold-templates approach mentioned above should work for now.
Or you are also free to just manually search and replace to add the word partial into any POCO class once it has been generated (though it would get overwritten every time you generated them again).
dnx ef dbcontext scaffold-templates EntityFramework.SqlServer
scaffold-templates command can be used to generate the EntityFramework.SqlServer.Design.DbContextTemplate.cshtml and EntityFramework.SqlServer.Design.EntityTypeTemplate.cshtml template files in the project directory to be used during scaffolding.
EntityTypeTemplate customization example to add partial class support:
....
....
#:namespace #Model.Namespace
#:{
#: public partial class #Model.EntityType.Name
#: {...
....
....
....
I am using 6.1.3 and models are generated as partials.
I have got the answers for setting up LdapContextSource and LdapTemplate without XML configurations from the SO question Best practice for configuring Spring LdapTemplate via annotations instead of XML?
What should be the annotation way for the below xml - automatically creating repository beans based on interfaces?
<ldap:repositories base-package="org.springframework.ldap.samples.useradmin.domain" />
Something like this.
#Configuration
#EnableLdapRepositories("org.springframework.ldap.samples.useradmin.domain")
public class LdapConfiguration { ... }
The #EnableLdapRepositories takes care of adding the correct configuration and scanning for repositories.
I am trying to use Entity Framework data migrations, as described in this post.
However, when I try to execute the Enable-Migrations step, I receive the following error in Package Manager Console:
The target context 'MyDataContext' is not constructible. Add a default constructor or provide an implementation of IDbContextFactory
So, I created a factory class that implements IDbContextFactory in the project that contains my DbContext class, but data migrations doesn't appear to recognize it.
Is there something that I should explicitly do to instruct data migrations to use this factory class?
I also hit this problem as i wrote my context to take a connection string name (and then used ninject to provide it).
The process you've gone through seems correct, here is a snippet of my class implementation if it's of any help:
public class MigrationsContextFactory : IDbContextFactory<MyContext>
{
public MyContext Create()
{
return new MyDBContext("connectionStringName");
}
}
That should be all you need.
Like #Soren pointed out, instead of using IDbContextFactory, not supported on some earlier EF Core releases (i.e. EF Core 2.1), we can implement IDesignTimeDbContextFactory<TContext>, which supports the missing ConnectionString parameter.
For a settings.json based aproach, which you can use with either of the referred interfaces, check #Arayn's sample which allows us to define "ConnectionStrings:DefaultConnection" value path
Update 1
According to #PaulWaldman's comment, on EF Core 5 support for IDbContextFactory was reintroduced. For further details, check his comment below.
Hallo all.
I'm using EclipseLink as JPA provider in our project. As described here
we have e big problem with char trimming with a DB char column with EclipseLink
I tried the way to remove the jdbc bind parameter but I cannot make this change for production environment: I tried to write my own SessionCustomizer but it doesn't seem to work.
public class ContrattoSessionCustomizer implements SessionCustomizer {
/**
* #see org.eclipse.persistence.config.SessionCustomizer#customize(org.eclipse.persistence.sessions.Session)
*/
#Override
public void customize(Session session) throws Exception {
System.out.println("hello.....");
DatabaseLogin login = (DatabaseLogin)session.getDatasourceLogin();
login.setShouldTrimStrings(false);
}
}
I would like to migrate from EclipseLink to another JPA provider; yesterday I tried with hibernate but unfortunately to migrate to this provider I need to change my domain model, since it seems that hibernate does not support some mapping definition that I used with eclipse link.
Is there another good provider to test without make changes to my domain model mapping?
Kind regards
Massimo
Can't see how changing providers will help you, as it is a database issue.
You seemed to state that you solved the issue by disabling parameter binding?
Are you registering your SessionCustomizer in your persistence.xml?