Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
cd58553
add deadline
github-classroom[bot] Dec 15, 2025
f043eb4
Add Main and Film class.
linneawardalhotmailcom Dec 16, 2025
86c2ac2
Add Director Class with getters and setters.
linneawardalhotmailcom Dec 16, 2025
5c33218
Add entity manager to Main.
linneawardalhotmailcom Dec 16, 2025
c5b0d5f
Add OneToMany in Director Class.
linneawardalhotmailcom Dec 16, 2025
3f3262f
Made yearOfDeath nullable.
linneawardalhotmailcom Dec 16, 2025
5125f3a
Fixed issues according to Coderabbit.
linneawardalhotmailcom Dec 17, 2025
bc6883c
Merge pull request #2 from ithsjava25/feature
linneawardalhotmailcom Dec 17, 2025
4d51d1f
Update README.md
mattiasbarth Dec 18, 2025
be0e7b4
Adds the basic framework for the CLI, printing menus based on the use…
EdvinSandgren Jan 7, 2026
5427500
Add files via upload
JohanHiths Jan 7, 2026
0135fb8
Adds the basic interface for the CRUD operations.
EdvinSandgren Jan 8, 2026
cc6a16e
Add files via upload
JohanHiths Jan 8, 2026
719fa14
Add files via upload
JohanHiths Jan 8, 2026
27cc14b
Add files via upload
JohanHiths Jan 8, 2026
d253f70
Add files via upload
JohanHiths Jan 9, 2026
438577a
Add files via upload
JohanHiths Jan 10, 2026
b27871c
Add files via upload
JohanHiths Jan 10, 2026
41fcca0
fixed issues that CodeRabbit highlighted
mattiasbarth Jan 12, 2026
02a6b0e
Fix some more issues from CodeRabbit, clean up some code.
mattiasbarth Jan 12, 2026
0066a05
Remove Director, Film and Main from Java-root.
mattiasbarth Jan 12, 2026
9bf2aca
update Directory.java and DirectorRepositoryImpl.java
mattiasbarth Jan 12, 2026
55889b0
Fixed problems identified by CodeRabbit
mattiasbarth Jan 12, 2026
887f1e1
Fixed problems identified by CodeRabbit
mattiasbarth Jan 12, 2026
ad87eed
Add FilmDTO, FilmRepository, FilmRepository, FilmService abd update F…
mattiasbarth Jan 12, 2026
daa00c8
Update FilmRepository, FilmRepositoryImpl and FilmService
mattiasbarth Jan 12, 2026
effd2b1
update FilmRepositoryImpl
mattiasbarth Jan 12, 2026
d330599
Updates Director Menu in CLI to implement methods in DirectorService
EdvinSandgren Jan 13, 2026
01bf50a
add and add code to SeriesDTO, SeriesRepository, SeriesRepositoryImpl…
mattiasbarth Jan 13, 2026
3c10c42
Add files via upload
JohanHiths Jan 13, 2026
9b8ceaa
update BaseRepositoryImpl, DirectorRepositoryImpl and SeriesService a…
mattiasbarth Jan 13, 2026
109988c
Updates menus to implement methods in Service classes for CRUD operat…
EdvinSandgren Jan 14, 2026
57b7d4e
Add files via upload
JohanHiths Jan 14, 2026
b043f55
Implements fixes highlighted by CodeRabbit
EdvinSandgren Jan 14, 2026
e2f2c57
Add files via upload
JohanHiths Jan 14, 2026
42d834d
Merge pull request #8 from ithsjava25/feature/CLI
JohanHiths Jan 14, 2026
cfde7f8
Merge pull request #7 from ithsjava25/johan
mattiasbarth Jan 14, 2026
ba087fb
update BaseRepositoryImpl, Director, FilmRepositoryImpl and SeriesRep…
mattiasbarth Jan 14, 2026
a6de7d4
Merge branch 'main' into mattias
mattiasbarth Jan 14, 2026
a1beeb5
Merge pull request #9 from ithsjava25/mattias
EdvinSandgren Jan 14, 2026
e91d463
Fixes various issues related to merges
EdvinSandgren Jan 14, 2026
e9fb1ae
Fixes minor issues identified by CodeRabbit
EdvinSandgren Jan 14, 2026
4929c8f
Adds some missing methods and changes a few field names
EdvinSandgren Jan 14, 2026
1ea47d7
Merge pull request #10 from ithsjava25/feature/merge
mattiasbarth Jan 14, 2026
af12454
Add files via upload
JohanHiths Jan 14, 2026
cff7dee
Add files via upload
JohanHiths Jan 14, 2026
3d148c3
Merge branch 'main' into johan
mattiasbarth Jan 14, 2026
5dff5c6
Add files via upload
JohanHiths Jan 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/_uV8Mn8f)
# 📘 Projektarbete: JPA + Hibernate med GitHub-flöde

Projektet genomförs som antingen en Java CLI-applikation eller med hjälp av JavaFX om ni vill ha ett grafiskt gränssnitt.
Expand All @@ -9,11 +10,11 @@ Kommunikation med databasen ska ske med JPA och Hibernate, enligt code first-met

## 🗓️ Veckoplanering med Checklista
### ✅ Vecka 1 – Grundläggning och struktur
- [ ] Klona GitHub-repo
- [ ] Konfigurera persistence.xml eller använd PersistenceConfiguration i kod
- [ ] Skapa entiteter och verifiera tabellgenerering
- [ ] Lägg till relationer (One-to-Many, Many-to-Many)
- [ ] Arbeta på feature-branches och använd pull requests för kodgranskning
- [x] Klona GitHub-repo
- [x] Konfigurera persistence.xml eller använd PersistenceConfiguration i kod
- [x] Skapa entiteter och verifiera tabellgenerering
- [x] Lägg till relationer (One-to-Many, Many-to-Many)
- [x] Arbeta på feature-branches och använd pull requests för kodgranskning

### ✅ Vecka 2 – Funktionalitet och relationer
- [ ] Dela upp funktioner mellan gruppmedlemmar
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/example/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example;

import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

public Long getId() {
return id;
}

}
93 changes: 93 additions & 0 deletions src/main/java/org/example/BaseRepositoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.example;

import jakarta.persistence.EntityManager;

import java.util.Optional;

public class BaseRepositoryImpl<T extends org.example.BaseEntity> implements Repository<T> {

protected EntityManager em;
protected Class<T> entityClass;


public BaseRepositoryImpl(Class<T> entityClass) {
this.entityClass = entityClass;
}

public void setEntityManager(EntityManager em) {
this.em = em;
}
Comment on lines +7 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

EntityManager can be null when methods are called.

The em field is only set via setEntityManager(), but all methods use it without null checks. If a caller forgets to set the EntityManager, any operation will throw NullPointerException.

Consider either:

  1. Requiring EntityManager in the constructor, or
  2. Adding a defensive check in methods.
🐛 Option 1: Require EntityManager in constructor
-    public BaseRepositoryImpl(Class<T> entityClass) {
+    public BaseRepositoryImpl(Class<T> entityClass, EntityManager em) {
         this.entityClass = entityClass;
+        this.em = em;
     }
-
-    public void setEntityManager(EntityManager em) {
-        this.em = em;
-    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public class BaseRepositoryImpl<T extends org.example.BaseEntity> implements Repository<T> {
protected EntityManager em;
protected Class<T> entityClass;
public BaseRepositoryImpl(Class<T> entityClass) {
this.entityClass = entityClass;
}
public void setEntityManager(EntityManager em) {
this.em = em;
}
public class BaseRepositoryImpl<T extends org.example.BaseEntity> implements Repository<T> {
protected EntityManager em;
protected Class<T> entityClass;
public BaseRepositoryImpl(Class<T> entityClass, EntityManager em) {
this.entityClass = entityClass;
this.em = em;
}
🤖 Prompt for AI Agents
In `@src/main/java/org/example/BaseRepositoryImpl.java` around lines 7 - 19, The
repository currently allows em to be null because it's only set via
setEntityManager; change BaseRepositoryImpl to require an EntityManager in the
constructor so em is always initialized: update the constructor signature of
BaseRepositoryImpl to accept EntityManager (e.g., BaseRepositoryImpl(Class<T>
entityClass, EntityManager em)) and assign this.em and this.entityClass there,
and remove or deprecate setEntityManager; after this change all methods using em
can assume non-null. If you prefer the defensive approach instead, add a private
helper (e.g., checkEntityManager() or requireEntityManager()) called at the
start of every public method to throw IllegalStateException with a clear message
if em == null, referencing the em field and setEntityManager method.




@Override
public T save(T entity) {
if (entity == null) {
throw new IllegalArgumentException("Entity cannot be null");
}
if (entity.getId() == null) {
em.persist(entity);
return entity;
} else {
return em.merge(entity);
}
}



public EntityManager getEntityManager() {
return em;
}

@Override
public Optional<T> findById(Long id) {
return Optional.ofNullable(em.find(entityClass, id));
}

@Override
public void delete(T entity) {
em.remove(em.contains(entity) ? entity : em.merge(entity));
}

@Override
public void deleteById(Long id) {
T entity = em.find(entityClass, id);
if (entity != null) {
em.remove(entity);
}
}

@Override
public Iterable<T> findAll() {
return em.createQuery(
"select e from " + entityClass.getSimpleName() + " e", entityClass
).getResultList();
}

@Override
public boolean existsById(Long id) {
Long count = em.createQuery(
"select count(e) from " + entityClass.getSimpleName() + " e where e.id = :id",
Long.class
).setParameter("id", id).getSingleResult();
return count > 0;

}

@Override
public long count() {

return em.createQuery("select count(e) from " + entityClass.getSimpleName() + " e", Long.class).getSingleResult();
}

@Override
public void flush() {
em.flush();
}

@Override
public void clear() {
em.clear();
}

}
6 changes: 6 additions & 0 deletions src/main/java/org/example/BusinessException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.example;

public class BusinessException extends Throwable {
public BusinessException(String s) {
}
Comment on lines +3 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Exception message is discarded; consider extending Exception instead of Throwable.

Two issues:

  1. Critical: The constructor parameter s is ignored. Without calling super(s), getMessage() will always return null, making debugging and logging ineffective.

  2. Convention: Extending Throwable directly is unusual. Business exceptions typically extend Exception (checked) or RuntimeException (unchecked). Throwable is the common ancestor of both Exception and Error, and Error is reserved for serious JVM-level problems.

🐛 Proposed fix
-public class BusinessException extends Throwable {
-    public BusinessException(String s) {
-    }
+public class BusinessException extends Exception {
+    public BusinessException(String message) {
+        super(message);
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public class BusinessException extends Throwable {
public BusinessException(String s) {
}
public class BusinessException extends Exception {
public BusinessException(String message) {
super(message);
}
}
🤖 Prompt for AI Agents
In `@src/main/java/org/example/BusinessException.java` around lines 3 - 5,
BusinessException currently extends Throwable and ignores the constructor
parameter `s`; change the class to extend Exception (or RuntimeException if you
want unchecked) and have the constructor call super(s) so getMessage() returns
the provided message; update any callers/throws declarations if you switch to
RuntimeException.

}
Loading