1313import java .util .Map ;
1414import java .util .Properties ;
1515
16+ import jakarta .persistence .PersistenceUnitTransactionType ;
1617import org .hibernate .CustomEntityDirtinessStrategy ;
1718import org .hibernate .EntityNameResolver ;
1819import org .hibernate .HibernateException ;
5556import org .hibernate .query .sqm .function .SqmFunctionDescriptor ;
5657import org .hibernate .resource .jdbc .spi .StatementInspector ;
5758import org .hibernate .service .ServiceRegistry ;
59+ import org .hibernate .tool .schema .Action ;
5860import org .hibernate .type .BasicType ;
5961import org .hibernate .type .SerializationException ;
6062import org .hibernate .usertype .UserType ;
@@ -441,6 +443,75 @@ public Configuration configure(File configFile) throws HibernateException {
441443 return this ;
442444 }
443445
446+ // New typed property setters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
447+
448+ /**
449+ * Set {@value AvailableSettings#SHOW_SQL}, {@value AvailableSettings#FORMAT_SQL},
450+ * and {@value AvailableSettings#HIGHLIGHT_SQL}.
451+ *
452+ * @param showSql should SQL be logged to console?
453+ * @param formatSql should logged SQL be formatted
454+ * @param highlightSql should logged SQL be highlighted with pretty colors
455+ */
456+ public Configuration showSql (boolean showSql , boolean formatSql , boolean highlightSql ) {
457+ setProperty ( AvailableSettings .SHOW_SQL , Boolean .toString (showSql ) );
458+ setProperty ( AvailableSettings .FORMAT_SQL , Boolean .toString (formatSql ) );
459+ setProperty ( AvailableSettings .HIGHLIGHT_SQL , Boolean .toString (highlightSql ) );
460+ return this ;
461+ }
462+
463+ /**
464+ * Set {@value AvailableSettings#HBM2DDL_AUTO}.
465+ *
466+ * @param action the {@link Action}
467+ */
468+ public Configuration setSchemaExportAction (Action action ) {
469+ setProperty ( AvailableSettings .HBM2DDL_AUTO , action .getExternalHbm2ddlName () );
470+ return this ;
471+ }
472+
473+ /**
474+ * Set {@value AvailableSettings#USER} and {@value AvailableSettings#PASS}.
475+ *
476+ * @param user the user id
477+ * @param pass the password
478+ */
479+ public Configuration setCredentials (String user , String pass ) {
480+ setProperty ( AvailableSettings .USER , user );
481+ setProperty ( AvailableSettings .PASS , pass );
482+ return this ;
483+ }
484+
485+ /**
486+ * Set {@value AvailableSettings#URL}.
487+ *
488+ * @param url the JDBC URL
489+ */
490+ public Configuration setJdbcUrl (String url ) {
491+ setProperty ( AvailableSettings .URL , url );
492+ return this ;
493+ }
494+
495+ /**
496+ * Set {@value AvailableSettings#DATASOURCE}.
497+ *
498+ * @param jndiName the JNDI name of the datasource
499+ */
500+ public Configuration setDatasource (String jndiName ) {
501+ setProperty ( AvailableSettings .DATASOURCE , jndiName );
502+ return this ;
503+ }
504+
505+ /**
506+ * Set {@value AvailableSettings#JAKARTA_TRANSACTION_TYPE}.
507+ *
508+ * @param transactionType the {@link PersistenceUnitTransactionType}
509+ */
510+ public Configuration setTransactionType (PersistenceUnitTransactionType transactionType ) {
511+ setProperty ( AvailableSettings .JAKARTA_TRANSACTION_TYPE , transactionType .toString () );
512+ return this ;
513+ }
514+
444515 // MetadataSources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
445516
446517 /**
@@ -694,6 +765,20 @@ public Configuration addAnnotatedClass(Class<?> annotatedClass) {
694765 return this ;
695766 }
696767
768+ /**
769+ * Read metadata from the annotations associated with the given classes.
770+ *
771+ * @param annotatedClasses The classes containing annotations
772+ *
773+ * @return this (for method chaining)
774+ */
775+ public Configuration addAnnotatedClasses (Class ... annotatedClasses ) {
776+ for (Class annotatedClass : annotatedClasses ) {
777+ addAnnotatedClass ( annotatedClass );
778+ }
779+ return this ;
780+ }
781+
697782 /**
698783 * Read package-level metadata.
699784 *
@@ -708,6 +793,22 @@ public Configuration addPackage(String packageName) throws MappingException {
708793 return this ;
709794 }
710795
796+ /**
797+ * Read package-level metadata.
798+ *
799+ * @param packageNames java package names
800+ *
801+ * @return this (for method chaining)
802+ *
803+ * @throws MappingException in case there is an error in the mapping data
804+ */
805+ public Configuration addPackages (String ... packageNames ) throws MappingException {
806+ for (String packageName : packageNames ) {
807+ addPackage ( packageName );
808+ }
809+ return this ;
810+ }
811+
711812 /**
712813 * Read all {@code .hbm.xml} mappings from a {@code .jar} file.
713814 * <p>
0 commit comments