Skip to content

Config/setting up persistance.xml#8

Merged
VonAdamo merged 2 commits intomainfrom
config/setting-up-persistance.xml
Dec 22, 2025
Merged

Config/setting up persistance.xml#8
VonAdamo merged 2 commits intomainfrom
config/setting-up-persistance.xml

Conversation

@VonAdamo
Copy link
Contributor

@VonAdamo VonAdamo commented Dec 22, 2025

Summary by CodeRabbit

  • Documentation

    • Added review deadline badge to README.
  • Chores

    • Added database configuration for MySQL connectivity.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

Walkthrough

Two files modified: README.md receives a documentation badge, and a new Jakarta Persistence configuration file is created at src/main/resources/META-INF/persistence.xml defining a JPA persistence unit for MySQL database connectivity with Hibernate settings.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added Markdown badge line linking to a review assignment due date
Database Configuration
src/main/resources/META-INF/persistence.xml
New JPA persistence unit configuration for Hibernate with MySQL (jdbc:mysql://localhost:3306/test), schema auto-generation enabled, SQL logging and formatting enabled

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify JDBC connection URL and credentials are correct for intended environment
  • Confirm hardcoded credentials ("root"/"root") are appropriate or should be externalized via environment variables
  • Validate that Hibernate properties (show_sql, format_sql, highlight_sql) are suitable for the deployment context (development vs. production)
  • Ensure entity classes are properly declared in the <class> elements (not visible in summary—confirm they exist)

Poem

A badge adorns the README's crown,
While persistence.xml joins the town,
MySQL awaits with open door,
Hibernate builds schemas galore! 🐰✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references the main change (persistence.xml configuration) but contains a spelling error ('persistance' instead of 'persistence'), and uses a slash separator that's unconventional for commit titles.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VonAdamo VonAdamo merged commit 6651b37 into ithsjava25:main Dec 22, 2025
1 of 2 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8794408 and 17572e7.

📒 Files selected for processing (2)
  • README.md
  • src/main/resources/META-INF/persistence.xml
🔇 Additional comments (4)
README.md (1)

1-1: LGTM!

The GitHub Classroom badge addition is standard practice for tracking assignment deadlines.

src/main/resources/META-INF/persistence.xml (3)

1-5: LGTM!

The Jakarta Persistence 3.2 namespace and schema declarations are correct.


14-17: SQL logging configuration is appropriate for development.

The enabled SQL logging (show_sql, format_sql, highlight_sql) is helpful for learning and debugging. The TODO comment correctly notes this should be disabled in production to avoid performance overhead and log clutter.


6-18: Add explicit MySQL JDBC driver specification to persistence.xml.

The MySQL Connector/J dependency is already present in your pom.xml with the latest version (9.5.0). However, add the explicit JDBC driver property to your persistence.xml configuration as a best practice:

<property name="jakarta.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>

While modern Hibernate can auto-detect the driver if it's on the classpath, explicitly specifying the driver makes the configuration more portable and maintainable.

Comment on lines +9 to +11
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test"/>
<property name="jakarta.persistence.jdbc.user" value="root"/>
<property name="jakarta.persistence.jdbc.password" value="root"/>
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

Remove hardcoded database credentials immediately.

Committing database credentials to version control is a critical security vulnerability. The credentials are exposed in the repository history and accessible to anyone with repository access.

🔎 Recommended approaches to secure credentials

Option 1: Environment variables (recommended for this project)

-            <property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test"/>
-            <property name="jakarta.persistence.jdbc.user" value="root"/>
-            <property name="jakarta.persistence.jdbc.password" value="root"/>
+            <property name="jakarta.persistence.jdbc.url" value="${DB_URL:jdbc:mysql://localhost:3306/test}"/>
+            <property name="jakarta.persistence.jdbc.user" value="${DB_USER}"/>
+            <property name="jakarta.persistence.jdbc.password" value="${DB_PASSWORD}"/>

Option 2: Separate properties file (not committed to git)

Create src/main/resources/db.properties and add it to .gitignore:

db.url=jdbc:mysql://localhost:3306/test
db.user=root
db.password=root

Then load these properties programmatically when creating the EntityManagerFactory.

Option 3: Use a template file

Commit persistence.xml.template with placeholders and document in README how to create the actual persistence.xml locally.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/main/resources/META-INF/persistence.xml around lines 9-11, remove the
hardcoded JDBC credentials and replace them with runtime-resolved values (e.g.,
${DB_URL}, ${DB_USER}, ${DB_PASSWORD}) or a lookup to a JNDI/data-source;
alternatively keep a persistence.xml.template with placeholders in repo and load
real values from environment variables or an external db.properties file (which
must be .gitignored) at runtime; update build/startup to inject those env vars
or properties and add instructions in README for local setup; ensure the
committed file no longer contains plaintext credentials and rotate any exposed
credentials immediately.

<property name="jakarta.persistence.jdbc.user" value="root"/>
<property name="jakarta.persistence.jdbc.password" value="root"/>
<!-- Automatically export the schema -->
<property name="jakarta.persistence.schema-generation.database.action" value="create"/>
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

Schema action "create" will drop all tables on every startup.

The create action drops and recreates the database schema on every application start, resulting in complete data loss. This is only appropriate for initial development or testing with disposable data.

Consider these alternatives:

  • update - updates the schema without dropping existing data (recommended for development)
  • validate - only validates the schema matches entities (recommended for production)
  • none or remove the property - no automatic schema management (production best practice)
🔎 Suggested fix for development workflow
-            <property name="jakarta.persistence.schema-generation.database.action" value="create"/>
+            <property name="jakarta.persistence.schema-generation.database.action" value="update"/>

For production, use:

<property name="jakarta.persistence.schema-generation.database.action" value="validate"/>
📝 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
<property name="jakarta.persistence.schema-generation.database.action" value="create"/>
<property name="jakarta.persistence.schema-generation.database.action" value="update"/>
🤖 Prompt for AI Agents
In src/main/resources/META-INF/persistence.xml around line 13 the property
jakarta.persistence.schema-generation.database.action is set to "create" which
drops and recreates the schema on every startup; change this to a safer value
depending on environment (for development set value="update", for production set
value="validate", or remove the property/use value="none"), and if you need
different behaviors across environments switch this property into
environment-specific configuration or use a profile/placeholder (e.g. replace
the literal with a variable that is injected at runtime) so production never
runs with "create".

This was referenced Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant