Equivalent of DataContext class from Entity Framework in Java/Spring boot/Spring Data

Viewed 258

I would like to know if there is an equivalent of DataContext class from Entity Framework in Java/Spring boot/Spring Data?

For example, in Entity Framework, I can determine DataContext class and add to it desired entities for work:

    public class DataContext : DbContext
{
    public DataContext(DbContextOptions<DataContext> options) : base(options) { }

    public DbSet<User> Users { get; set; }
    public DbSet<Photo> Photos { get; set; }
}

and then work with DataContext object to access database operations:

public class DataService : IDataService
{
    private readonly DataContext _context;

    public DataService(DataContext context)
    {
        _context = context;
    }

    public void Add<T>(T entity)
    {
        _context.Add(entity);
    }
}

private readonly IDataService _dataService;
_dataService.Add<User>(user);
_dataService.Add<Photo>(photo);
0 Answers
Related